[bittorrent] compact ip problem

Ben Gotow bengotow at gmail.com
Wed Aug 22 15:47:09 EDT 2007


Hey Dazen,

You might want to check the endianness of your data. I'm not sure how  
java works, so you may have to specifically put your data structure  
into big endian mode before setting values.

Also, I can't really tell from your code but it looks like  
inetAddress.getAddress() may return a string? You don't actually want  
to send the address as a string. You want to save each section of the  
IP address as a unsigned 8 bit integer. So if I have the IP address  
129.59.70.23, then I would say:

compactIP[0] = (byte)(129)
compactIP[1] = (byte)(59)
compactIP[2] = (byte)(70)
compactIP[3] = (byte)(23)

haha please excuse my syntax. I really don't know Java. But here's  
some code I wrote a while ago that decodes a compact response. It may  
help you!

	//create a memoryblock object and fill it with the "peers" section
	//of the bencoded data.

       mb = NewMemoryBlock(d.value("peers").StringValue.Len+2)
       mb.LittleEndian = false
       mb.cstring(0) = d.value("peers").StringValue

       //step through each set of 6 bytes. IP is first four, port is  
last two.

       for x=0 to mb.size-3 step 6
         ip =str(mb.uInt8Value(x))+"."+str(mb.uInt8Value(x+1))+"."+str 
(mb.uInt8Value(x+2))+"."+str(mb.uInt8Value(x+3))
         port = mb.uInt16Value(x+4)
         a = peerNewWithProperties(ip,"",port)
       next

Hope that helps,

- Ben Gotow


On Aug 22, 2007, at 3:07 PM, Dazen D wrote:

> Hi. I'm having some problems sending announce responses
> with compact ips on it. Apparently the clients don't
> recognize the compact ip that i'm generating (using java
> code). If i send regular ips and ports, it works fine.
>
> To generate the four first bytes (IP) i use the code:
>
>     String ip = (...)
>     InetAddress inetAddress = InetAddress.getByName(ip);
>     byte[] rawAddress = inetAddress.getAddress();
>
> For the other two bytes (port):
>
>     compactIP[4] = (byte)(port >> 8);
>     compactIP[5] = (byte)(port & 0xff);
>
> (which is apparently how azureus do that)
>
>
> The response that is arriving to the client is:
>
> d8:intervali1800e8:completei1e10:incompletei1e5:peers6:XXXXYYe
>
> where "XXXX" are the IP bytes and "YY" the port bytes.
>
>
> I even tried another format for the response, which some trackers use:
>
> d8:intervali1800e8:completei1e10:incompletei1e5:peerspeersleeXXXXYY
>
> but it was the same.
>
>
> Any idea about what could be wrong?
>
> Thanks a lot.
> _______________________________________________
> BitTorrent mailing list
> BitTorrent at lists.ibiblio.org
> http://lists.ibiblio.org/mailman/listinfo/bittorrent




More information about the BitTorrent mailing list