public void route(int dstGuid, RPC rpc) throws IOException { Friend f = netMan.getFriendManager().getFriend(dstGuid); if (f != null && f.getFriendConnection() != null) { if (T.t) { T.info("Rerouting package to friend"); } f.getFriendConnection().send(rpc); } else { // note that one of our friends COULD actually be a closer Route to the destination. But this // way we send // the rpc the same way back as be got it. No biggie probably. rpc.init(this); Packet p = createRPCPacket(rpc); send(new Route(netMan.getFriendManager().getMyGUID(), dstGuid, p)); } }
public void send(int dstGuid, RPC rpc) throws IOException { if (dstGuid != getRemoteUserGUID()) { if (T.t) { T.debug("Rerouting package " + rpc + " to " + dstGuid); } route(dstGuid, rpc); } else { if (!rpc.isInitialized()) { rpc.init( this); // under certain conditions a rpc can be reused and sent a second time - then // it's the first init call that counts. Don't make it twice. } Packet p = createRPCPacket(rpc); if (T.t) { T.debug("--> Sending " + rpc + " (" + p.getPos() + " bytes) to " + getRemoteFriend()); } send(p); } }
public void received(int fromGuid, int hops, Packet packet, RPC outerRPC) throws IOException { int id = packet.readByte(); RPC rpc = RPCFactory.newInstance(id); if (rpc == null) { if (T.t) { T.warn("Skipping unknown RPC ID: " + id + "!!!"); } packet.skip(packet.getAvailable()); // skip contents of packet return; } else { if (T.t) { if (outerRPC == null) { T.debug( "<-- Recived " + rpc + " (" + (packet.getAvailable() + 1) + " bytes) from " + netMan.getFriendManager().getNode(fromGuid) + " (con: " + getRemoteFriend() + ")"); // +1 because we read one byte above } else { T.debug( "<----- Recived " + rpc + " (" + (packet.getAvailable() + 1) + " bytes) from " + netMan.getFriendManager().getNode(fromGuid) + " (con: " + getRemoteFriend() + ", outer: " + outerRPC + ")"); // +1 because we read one byte above } } rpc.init(this, fromGuid, hops); rpc.execute(packet); signalReceived(rpc); } }
public void broadcast(short msgId, RPC rpc) throws IOException { rpc.init(this); Packet p = createRPCPacket(rpc); send(new Broadcast(netMan.getFriendManager().getMyGUID(), msgId, p)); }