use of com.biglybt.core.peermanager.PeerManagerRoutingListener in project BiglyBT by BiglySoftware.
the class HTTPNetworkManager method reRoute.
protected void reRoute(final HTTPNetworkConnection old_http_connection, final byte[] old_hash, final byte[] new_hash, final String header) {
final NetworkConnection old_connection = old_http_connection.getConnection();
PeerManagerRegistration reg_data = PeerManager.getSingleton().manualMatchHash(old_connection.getEndpoint().getNotionalAddress(), new_hash);
if (reg_data == null) {
old_http_connection.close("Re-routing failed - registration not found");
return;
}
final Transport transport = old_connection.detachTransport();
old_http_connection.close("Switching torrents");
final NetworkConnection new_connection = NetworkManager.getSingleton().bindTransport(transport, new HTTPMessageEncoder(), new HTTPMessageDecoder(header));
PeerManager.getSingleton().manualRoute(reg_data, new_connection, new PeerManagerRoutingListener() {
@Override
public boolean routed(PEPeerTransport peer) {
HTTPNetworkConnection new_http_connection;
if (header.contains("/webseed")) {
new_http_connection = new HTTPNetworkConnectionWebSeed(HTTPNetworkManager.this, new_connection, peer);
} else if (header.contains("/files/")) {
new_http_connection = new HTTPNetworkConnectionFile(HTTPNetworkManager.this, new_connection, peer);
} else {
return (false);
}
// fake a wakeup so pre-read header is processed
new_http_connection.readWakeup();
return (true);
}
});
}
Aggregations