On 5/15/06, Tyler Pitchford <[EMAIL PROTECTED]> wrote:
I can't seem to find an answer to this and I am getting very spotting
results (looks like threading issues). I'm tyring to build a
BitTorrent Filter for MINA, but I can't seem to get everything working
correctly.
To understand that situation, you'll need a little background on the
BT protocol. When connecting to a peer a "handshake" message is sent,
nothing unusual here, right? Well, sadly the handshake doesn't follow
the wire header format. The Handshake uses a singly byte for it's
header and the wire messages use a 4 byte header.
Anyway, to handle it "cleanly" (probably not the fastest, but nicely
architecturally), I developed a PeerWireHandshakeCodecFactory and a
PeerWireCodecFactory. I could just change the header length, once the
handshake was received, but I don't want to mix the handshake / wire
messages, because in my opinion they should be handled separately.
Anyway, I'm currently trying to do this is once the handshake response
is received (handshake part is working correctly), I call:
public void messageReceived(IoSession session, Object message){
if (message instanceof PeerWireHandshakeMessage) {
synchronized(session){
session.getFilterChain().remove("handshakeFilter");
ProtocolCodecFactory codec = new PeerWireCodecFactory();
session.getFilterChain().addFirst("peerWireFilter", new
ProtocolCodecFilter(codec));
}
}
The problem I'm seeing is that the PeerWire Encoders/Decoders never
seem to get called. I've only seen them called one time, while
debugged, which makes me think it's a threading issue. Any help /
advice would be lovely. I'm not opposed to changing the architecture,
if needed.
Do you get a raw ByteBuffer in messageReceived() when you switch the filter
instead PeerWireCodecFactory is active? If so, it's not a bug but you need
a little bit more coding. Otherwise, it can be a bug. Please let us know
first.
P.S. you should update the mailing list link of the website. Sorry
about the email to [EMAIL PROTECTED]
Thanks for the heads up. We will fix it soon.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP key fingerprints:
* E167 E6AF E73A CBCE EE41 4A29 544D DE48 FE95 4E7E
* B693 628E 6047 4F8F CFA4 455E 1C62 A7DC 0255 ECA6