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.
Cheers,
Tyler