31.05.2013 Views

progettazione e realizzazione in java di una rete peer to peer ...

progettazione e realizzazione in java di una rete peer to peer ...

progettazione e realizzazione in java di una rete peer to peer ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Documentazione del proget<strong>to</strong><br />

Table of buckets<br />

This table is built <strong>di</strong>rectly <strong>in</strong> the construc<strong>to</strong>r of the class KadAdt. It is implemen-<br />

ted by an array of Object. Each of these Object is an <strong>in</strong>stance of <strong>di</strong>fferent sizes 2<br />

dopArray.<br />

dopArray is built coupl<strong>in</strong>g two simple arrays:<br />

1. Long[];<br />

2. tripla[].<br />

The first one s<strong>to</strong>res a long value 3 that represents the timestamp obta<strong>in</strong>ed<br />

runn<strong>in</strong>g the <strong>java</strong> method System.currentTimeMillis. A -1 value <strong>in</strong> this field denotes<br />

an empty tripla. So the eras<strong>in</strong>g procedure 4 consists simply <strong>in</strong> putt<strong>in</strong>g a -1 <strong>in</strong><br />

the long cell.<br />

The second array holds <strong>in</strong>stances of the class tripla.<br />

The class tripla is a collection of three <strong>di</strong>fferent Object. It is conceived <strong>to</strong><br />

represent a node on the net. In fact it is structured <strong>in</strong> the follow<strong>in</strong>g way:<br />

InetAddress ip represents the ip address of the node;<br />

<strong>in</strong>t port represents the port address on which the node is listen<strong>in</strong>g;<br />

Str<strong>in</strong>g Hash represents the ID of the node.<br />

Table of random bytes<br />

This table is built us<strong>in</strong>g brand new own made class called triplArray. This class<br />

is composed by three <strong>di</strong>fferent simple arrays:<br />

1. Long[];<br />

2. Byte[];<br />

3. Object[].<br />

The first one s<strong>to</strong>res a long value 5 that represents the timestamp obta<strong>in</strong>ed<br />

runn<strong>in</strong>g the <strong>java</strong> method System.currentTimeMillis. A -1 value <strong>in</strong> this field denotes<br />

2 The size of the dopArray is def<strong>in</strong>ed accord<strong>in</strong>g <strong>to</strong> the kademlia policies.<br />

3 A long encapsulated <strong>in</strong> a Long.<br />

4 And the <strong>in</strong>itialization.<br />

5 A long encapsulated <strong>in</strong> a Long.<br />

40

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!