From: <th...@us...> - 2008-04-15 22:57:26
|
Revision: 1628 http://azsmrc.svn.sourceforge.net/azsmrc/?rev=1628&view=rev Author: the8472 Date: 2008-04-15 15:57:23 -0700 (Tue, 15 Apr 2008) Log Message: ----------- -fixed message/transaction ID to properly respond to other nodes extend it to a larger keyspace -send version (unofficial extension also used by ?\194?\181T) -reduced number of concurrent ping-probes to questionable or potentially impersonated nodes Modified Paths: -------------- azsmrcplugins/trunk/lbms/plugins/mldht/azureus/MlDHTPlugin.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHT.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHTConstants.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/KBucket.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCCall.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServerBase.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceRequest.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceResponse.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/ErrorMessage.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeRequest.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeResponse.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersRequest.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersResponse.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageBase.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageDecoder.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingRequest.java azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingResponse.java Modified: azsmrcplugins/trunk/lbms/plugins/mldht/azureus/MlDHTPlugin.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/azureus/MlDHTPlugin.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/azureus/MlDHTPlugin.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -126,7 +126,10 @@ logChannel.addListener(logListener); - dht = new DHT(); + + String version = pluginInterface.getPluginVersion(); + + dht = new DHT(version != null ? Integer.parseInt(version.replaceAll("[^0-9]", "")) : -1); DHT.setLogger(new DHTLogger() { /* (non-Javadoc) * @see lbms.plugins.mldht.kad.DHTLogger#log(java.lang.String) Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHT.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHT.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHT.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -82,7 +82,8 @@ private DHTStats stats; private DHTStatus status; - public DHT() { + public DHT(int version) { + DHTConstants.version = version; expire_timer = new ExpireTimer(); stats = new DHTStats(); status = DHTStatus.Stopped; @@ -305,7 +306,7 @@ public int getPort () { return port; } - + /* (non-Javadoc) * @see lbms.plugins.mldht.kad.DHTBase#getStats() */ @@ -408,6 +409,9 @@ //scheduler.shutdown(); logInfo("Stopping DHT"); + for (Task t : tman.getActiveTasks()) + t.kill(); + srv.stop(); try { node.saveTable(table_file); Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHTConstants.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHTConstants.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/DHTConstants.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -40,9 +40,15 @@ public static final String TYP = "y"; public static final String ARG = "a"; public static final String ERR = "e"; + public static final String VER = "v"; public static final String BOOTSTRAP_NODE = "router.bittorrent.com"; public static InetAddress BOOTSTRAP_NODE_ADDRESS = null; public static final int BOOTSTRAP_PORT = 6881; + public static String getVersion() { + return "Az" + new String(new byte[] { (byte) (version >> 8), (byte) (version & 0xff) }); + } + static int version = 0; + } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/KBucket.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/KBucket.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/KBucket.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -35,6 +35,12 @@ final KBucketEntry toReplace; final KBucketEntry replacement; + + public boolean equals(Object obj) { + if(!(obj instanceof ReplacementEntry)) + return false; + return toReplace.equals(((ReplacementEntry)obj).toReplace); + } } // any modifying actions to entries must happen through removeAndInsert (which is synchronized)! @@ -226,13 +232,18 @@ private boolean pingEntry(KBucketEntry entry, KBucketEntry replacement) { + ReplacementEntry rEntry = new ReplacementEntry(entry,replacement); + // don't ping if there already is an outstanding ping + if(pending_entries_busy_pinging.containsValue(rEntry)) + return false; + PingRequest p = new PingRequest(node.getOurID()); p.setDestination(entry.getAddress()); RPCCall c = srv.doCall(p); if (c != null) { c.addListener(this); // add the pending entry - pending_entries_busy_pinging.put(c, new ReplacementEntry(entry,replacement)); + pending_entries_busy_pinging.put(c, rEntry); return true; } return false; Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCCall.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCCall.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCCall.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -114,7 +114,7 @@ private void onCallTimeout () { if (msg != null) { - DHT.logDebug("RPCCall timed out ID: " + (msg.getMTID() & 0xFF)); + DHT.logDebug("RPCCall timed out ID: " + new String(msg.getMTID())); try { rpc.timedOut(msg.getMTID()); } catch (Exception e) { Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServer.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -6,6 +6,7 @@ import java.net.InetSocketAddress; import java.net.SocketException; import java.util.ArrayList; +import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -23,22 +24,47 @@ * */ public class RPCServer implements Runnable, RPCServerBase { + + private static final class ByteWrapper { + private final byte[] arr; + private final int hash; + + ByteWrapper(byte[] a) + { + arr = a; + hash = Arrays.hashCode(a); + } + + public ByteWrapper(short s) + { + this(new byte[] {(byte)(s<<8),(byte)(s&0xff)}); + } + + @Override + public int hashCode() { + return hash; + } + + @Override + public boolean equals(Object obj) { + return obj instanceof ByteWrapper && Arrays.equals(arr,((ByteWrapper)obj).arr); + } + } - private DatagramSocket sock; - private DHT dh_table; - private Map<Integer, RPCCallBase> calls; - private List<RPCCallBase> call_queue; - private byte next_mtid; - private volatile boolean running; - private Thread thread; + private DatagramSocket sock; + private DHT dh_table; + private Map<ByteWrapper, RPCCallBase> calls; + private List<RPCCallBase> call_queue; + private short next_mtid; + private volatile boolean running; + private Thread thread; + private int numReceived; + private int numSent; + private RPCStats stats; - private int numReceived; - private int numSent; - private RPCStats stats; - public RPCServer (DHT dh_table, int port) throws SocketException { //, Object parent sock = new DatagramSocket(port); - calls = new HashMap<Integer, RPCCallBase>(); + calls = new HashMap<ByteWrapper, RPCCallBase>(); call_queue = new ArrayList<RPCCallBase>(128); stats = new RPCStats(); this.dh_table = dh_table; @@ -116,8 +142,8 @@ * @see lbms.plugins.mldht.kad.RPCServerBase#doCall(lbms.plugins.mldht.kad.messages.MessageBase) */ public RPCCall doCall (MessageBase msg) { - byte start = next_mtid; - while (calls.containsKey(next_mtid & 0xFF)) { + short start = next_mtid; + while (calls.containsKey(new ByteWrapper(next_mtid))) { next_mtid++; if (next_mtid == start) // if this happens we cannot do any calls { @@ -132,20 +158,20 @@ msg.setMTID(next_mtid++); sendMessage(msg); RPCCall c = new RPCCall(this, msg, false); - calls.put(msg.getMTID() & 0xFF, c); + calls.put(new ByteWrapper(msg.getMTID()), c); return c; } /* (non-Javadoc) * @see lbms.plugins.mldht.kad.RPCServerBase#timedOut(byte) */ - public void timedOut (byte mtid) { + public void timedOut (byte[] mtid) { // delete the call - RPCCallBase c = calls.get(mtid & 0xFF); + RPCCallBase c = calls.get(new ByteWrapper(mtid)); if (c != null) { stats.addTimeoutMessageToCount(c.getRequest()); dh_table.timeout(c.getRequest()); - calls.remove(mtid & 0xFF); + calls.remove(new ByteWrapper(mtid)); } doQueuedCalls(); } @@ -162,8 +188,8 @@ /* (non-Javadoc) * @see lbms.plugins.mldht.kad.RPCServerBase#findCall(byte) */ - public RPCCallBase findCall (byte mtid) { - return calls.get(mtid & 0xFF); + public RPCCallBase findCall (byte[] mtid) { + return calls.get(new ByteWrapper(mtid)); } /// Get the number of active calls @@ -218,17 +244,17 @@ if (msg != null) { DHT.logDebug("RPC Packet was: " + msg.getMethod() + " Type:" + msg.getType() + " MessageID: " - + (msg.getMTID() & 0xFF)); + + new String(msg.getMTID())); stats.addReceivedMessageToCount(msg); msg.setOrigin(new InetSocketAddress(p.getAddress(), p.getPort())); msg.apply(dh_table); // erase an existing call if (msg.getType() == Type.RSP_MSG - && calls.containsKey(msg.getMTID() & 0xFF)) { + && calls.containsKey(new ByteWrapper(msg.getMTID()))) { // delete the call, but first notify it off the response - RPCCallBase c = calls.get(msg.getMTID() & 0xFF); + RPCCallBase c = calls.get(new ByteWrapper(msg.getMTID())); c.response(msg); - calls.remove(msg.getMTID() & 0xFF); + calls.remove(new ByteWrapper(msg.getMTID())); doQueuedCalls(); } } @@ -245,7 +271,7 @@ stats.addSentMessageToCount(msg); send(msg.getDestination(), msg.encode()); DHT.logDebug("RPC Send Message: " + msg.getMethod() + " Type:" - + msg.getType() + " MessageID: " + (msg.getMTID() & 0xFF)); + + msg.getType() + " MessageID: " + new String(msg.getMTID())); } catch (IOException e) { e.printStackTrace(); } @@ -266,14 +292,14 @@ while (call_queue.size() > 0 && calls.size() < 256) { RPCCallBase c = call_queue.remove(0); - while (calls.containsKey(next_mtid & 0xFF)) { + while (calls.containsKey(new ByteWrapper(next_mtid))) { next_mtid++; } MessageBase msg = c.getRequest(); msg.setMTID(next_mtid++); sendMessage(msg); - calls.put(msg.getMTID() & 0xFF, c); + calls.put(new ByteWrapper(msg.getMTID()), c); c.start(); } } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServerBase.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServerBase.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/RPCServerBase.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -37,7 +37,7 @@ * A call was timed out. * @param mtid mtid of call */ - public void timedOut (byte mtid); + public void timedOut (byte[] mtid); /** * Ping a node, we don't care about the MTID. @@ -50,7 +50,7 @@ * @param mtid The mtid * @return The call */ - public RPCCallBase findCall (byte mtid); + public RPCCallBase findCall (byte[] mtid); /// Get the number of active calls public int getNumActiveRPCCalls (); Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceRequest.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceRequest.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceRequest.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -54,8 +54,9 @@ inner.put("token", token.getHash()); base.put(DHTConstants.REQ, "announce_peer"); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.REQ); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceResponse.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceResponse.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/AnnounceResponse.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -20,7 +20,7 @@ * @param mtid * @param id */ - public AnnounceResponse (byte mtid, Key id) { + public AnnounceResponse (byte[] mtid, Key id) { super(mtid, Method.ANNOUNCE_PEER, Type.RSP_MSG, id); } @@ -43,8 +43,9 @@ base.put(DHTConstants.RSP, inner); inner.put("id", id.getHash()); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.RSP); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/ErrorMessage.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/ErrorMessage.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/ErrorMessage.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -18,7 +18,7 @@ * @param id * @param msg */ - public ErrorMessage (byte mtid, int code, String msg) { + public ErrorMessage (byte[] mtid, int code, String msg) { super(mtid, Method.NONE, Type.ERR_MSG, null); this.msg = msg; this.code = code; Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeRequest.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeRequest.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeRequest.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -23,7 +23,7 @@ * @param target */ public FindNodeRequest (Key id, Key target) { - super((byte) 0xFF, Method.FIND_NODE, Type.REQ_MSG, id); + super(new byte[] { (byte)0xff }, Method.FIND_NODE, Type.REQ_MSG, id); this.target = target; } @@ -47,8 +47,9 @@ inner.put("target", target.getHash()); base.put(DHTConstants.REQ, "find_node"); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.REQ); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeResponse.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeResponse.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/FindNodeResponse.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -23,7 +23,7 @@ * @param id * @param nodes */ - public FindNodeResponse (byte mtid, Key id, byte[] nodes) { + public FindNodeResponse (byte[] mtid, Key id, byte[] nodes) { super(mtid, Method.FIND_NODE, Type.RSP_MSG, id); this.nodes = nodes; } @@ -47,8 +47,9 @@ inner.put("id", id.getHash()); inner.put("nodes", nodes); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.RSP); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersRequest.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersRequest.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersRequest.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -23,7 +23,7 @@ * @param info_hash */ public GetPeersRequest (Key id, Key info_hash) { - super((byte) 0xFF, Method.GET_PEERS, Type.REQ_MSG, id); + super(new byte[] {(byte) 0xFF}, Method.GET_PEERS, Type.REQ_MSG, id); this.info_hash = info_hash; } @@ -47,8 +47,9 @@ inner.put("info_hash", info_hash.getHash()); base.put(DHTConstants.REQ, "get_peers"); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.REQ); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersResponse.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersResponse.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/GetPeersResponse.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -31,7 +31,7 @@ * @param data * @param token */ - public GetPeersResponse (byte mtid, Key id, byte[] data, Key token) { + public GetPeersResponse (byte[] mtid, Key id, byte[] data, Key token) { super(mtid, Method.GET_PEERS, Type.RSP_MSG, id); this.data = data; this.token = token; @@ -43,7 +43,7 @@ * @param items * @param token */ - public GetPeersResponse (byte mtid, Key id, List<DBItem> items, Key token) { + public GetPeersResponse (byte[] mtid, Key id, List<DBItem> items, Key token) { super(mtid, Method.GET_PEERS, Type.RSP_MSG, id); this.items = items; this.token = token; @@ -78,8 +78,9 @@ innerMap.put("values", itemsList); } - base.put(DHTConstants.TID, new String(new byte[] { mtid }, "UTF-8")); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.RSP); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageBase.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageBase.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageBase.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -13,13 +13,13 @@ */ public abstract class MessageBase { - protected byte mtid; + protected byte[] mtid; protected Method method; protected Type type; protected Key id; protected InetSocketAddress origin; - public MessageBase (byte mtid, Method m, Type type, Key id) { + public MessageBase (byte[] mtid, Method m, Type type, Key id) { this.mtid = mtid; this.method = m; this.type = type; @@ -65,14 +65,18 @@ } /// Get the MTID - public byte getMTID () { + public byte[] getMTID () { return mtid; } /// Set the MTID - public void setMTID (byte m) { + public void setMTID (byte[] m) { mtid = m; } + + public void setMTID (short m) { + mtid = new byte[] {(byte)(m<<8),(byte)(m&0xff)}; + } /// Get the id of the sender public Key getID () { Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageDecoder.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageDecoder.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/MessageDecoder.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -55,16 +55,16 @@ return null; } - byte mtid = 0; + byte[] mtid; if (map.get(DHTConstants.TID) instanceof Long) { - mtid = ((Long) map.get(DHTConstants.TID)).byteValue(); + return null;//mtid = ((Long) map.get(DHTConstants.TID)).byteValue(); } else if (map.get(DHTConstants.TID) instanceof byte[]) { byte[] ba = (byte[]) map.get(DHTConstants.TID); - if (ba == null || ba.length == 0) { + if (ba == null || ba.length < 1) { return null; } - mtid = ba[0]; + mtid = ba; } else { return null; } @@ -86,16 +86,16 @@ return null; } - byte mtid = 0; + byte[] mtid; if (map.get(DHTConstants.TID) instanceof Long) { - mtid = ((Long) map.get(DHTConstants.TID)).byteValue(); + return null;//mtid = ((Long) map.get(DHTConstants.TID)).byteValue(); } else if (map.get(DHTConstants.TID) instanceof byte[]) { byte[] ba = (byte[]) map.get(DHTConstants.TID); - if (ba == null || ba.length == 0) { + if (ba == null || ba.length != 2) { return null; } - mtid = ba[0]; + mtid = ba; } else { return null; } @@ -103,7 +103,7 @@ // find the call RPCCallBase c = srv.findCall(mtid); if (c == null) { - DHT.logDebug("Cannot find RPC call for response: " + (mtid & 0xFF)); + DHT.logDebug("Cannot find RPC call for response: " + new String(mtid)); return null; } @@ -117,7 +117,7 @@ * @return */ private static MessageBase parseResponse (Map<String, Object> map, - Method msgMethod, byte mtid) { + Method msgMethod, byte[] mtid) { Map<String, Object> args = (Map<String, Object>) map.get(DHTConstants.RSP); if (args == null || !args.containsKey("id")) { return null; @@ -162,7 +162,7 @@ if (((byte[])vals.get(i)).length < 6) { continue; } - dbl.add(new DBItem((byte[])vals.get(i),0)); + dbl.add(new DBItem((byte[])vals.get(i))); } return new GetPeersResponse(mtid, id, dbl, token); } else if (args.containsKey("nodes")) { @@ -209,16 +209,16 @@ Key id = new Key(hash); - byte mtid = 0; + byte[] mtid; if (map.get(DHTConstants.TID) instanceof Long) { - mtid = ((Long) map.get(DHTConstants.TID)).byteValue(); + return null;//mtid = ((Long) map.get(DHTConstants.TID)); } else if (map.get(DHTConstants.TID) instanceof byte[]) { byte[] ba = (byte[]) map.get(DHTConstants.TID); - if (ba == null || ba.length == 0) { + if (ba == null || ba.length < 1) { return null; } - mtid = ba[0]; + mtid = ba; } else { return null; } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingRequest.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingRequest.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingRequest.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -20,7 +20,7 @@ * @param id */ public PingRequest (Key id) { - super((byte) 0xFF, Method.PING, Type.REQ_MSG, id); + super(new byte[] {(byte) 0xFF}, Method.PING, Type.REQ_MSG, id); } /* (non-Javadoc) @@ -42,8 +42,9 @@ inner.put("id", id.getHash()); base.put(DHTConstants.REQ, "ping"); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.REQ); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } Modified: azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingResponse.java =================================================================== --- azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingResponse.java 2008-04-15 19:51:47 UTC (rev 1627) +++ azsmrcplugins/trunk/lbms/plugins/mldht/kad/messages/PingResponse.java 2008-04-15 22:57:23 UTC (rev 1628) @@ -20,7 +20,7 @@ * @param mtid * @param id */ - public PingResponse (byte mtid, Key id) { + public PingResponse (byte[] mtid, Key id) { super(mtid, Method.PING, Type.RSP_MSG, id); } @@ -42,8 +42,9 @@ base.put(DHTConstants.RSP, inner); inner.put("id", id.getHash()); - base.put(DHTConstants.TID, new byte[] { mtid }); + base.put(DHTConstants.TID, mtid); base.put(DHTConstants.TYP, DHTConstants.RSP); + base.put(DHTConstants.VER, DHTConstants.getVersion()); return BEncoder.encode(base); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |