mardi 31 mars 2015

Getting scrambled replies from DHT bootsraps for Bittorrent


Vote count:

0




I'm trying to implement a DHT node in the Bittorrent mainline. So far I got a connection in and out against a bootstrap node, the query seems to be fine according to some bencoded examples but part of the result I'm getting back is all scrambled (the parts containing the actual data):



d2:ip6:µ§ û©Å1:rd2:id20:ëÿ6isQÿJì)ͺ«òûãF|Âge1:t2:aa1:y1:re


This is my code so far:



private static String serverName = "router.utorrent.com";
private static int port = 6881;
private static String packet = "d1:ad2:id20:abcdefghij0123456789e1:q4:ping1:t2:aa1:y1:qe";
public static void main(String[] args) {

int port = Main.port;
InetAddress address = InetAddress.getByName(Main.serverName);
DatagramSocket socket = new DatagramSocket();

byte[] buf = Main.packet.getBytes();
DatagramPacket packet = new DatagramPacket(buf, buf.length, address, port);
socket.send(packet);
byte[] recBuf = new byte[2048];
DatagramPacket recPacket = new DatagramPacket(recBuf, recBuf.length);

socket.receive(recPacket);

System.out.println(new String(extract(recPacket)));
}

private static byte[] extract(DatagramPacket packet) {
byte[] data = packet.getData();
int offset = packet.getOffset();
int length = packet.getLength();

byte[] copy = new byte[length];
System.arraycopy(data, offset, copy, 0, copy.length);

return copy;
}


I'm not sure whether I have a chartset problem or there is some encoding I couldn't find specified anywhere.



asked 1 min ago

dElo

63






Getting scrambled replies from DHT bootsraps for Bittorrent

Aucun commentaire:

Enregistrer un commentaire