1 /*
2  * File    : PRUDPPacketReplyConnect.java
3  * Created : 20-Jan-2004
4  * By      : parg
5  *
6  * Azureus - a Java Bittorrent client
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details ( see the LICENSE file ).
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
21  */
22 
23 package com.aelitis.azureus.core.dht.transport.udp.impl;
24 
25 /**
26  * @author parg
27  *
28  */
29 
30 import java.io.*;
31 import java.net.InetSocketAddress;
32 
33 import com.aelitis.azureus.core.dht.transport.DHTTransportContact;
34 import com.aelitis.azureus.core.dht.transport.udp.DHTTransportUDP;
35 import com.aelitis.azureus.core.dht.transport.udp.impl.packethandler.DHTUDPPacketNetworkHandler;
36 
37 public class
38 DHTUDPPacketReplyFindNode
39 	extends DHTUDPPacketReply
40 {
41 	private DHTTransportContact[]	contacts;
42 	private int						random_id;
43 	private int						node_status	= DHTTransportUDPContactImpl.NODE_STATUS_UNKNOWN;
44 	private int						estimated_dht_size;
45 
46 	public
DHTUDPPacketReplyFindNode( DHTTransportUDPImpl transport, DHTUDPPacketRequestFindNode request, DHTTransportContact local_contact, DHTTransportContact remote_contact )47 	DHTUDPPacketReplyFindNode(
48 		DHTTransportUDPImpl				transport,
49 		DHTUDPPacketRequestFindNode		request,
50 		DHTTransportContact				local_contact,
51 		DHTTransportContact				remote_contact )
52 	{
53 		super( transport, DHTUDPPacketHelper.ACT_REPLY_FIND_NODE, request, local_contact, remote_contact );
54 	}
55 
56 	protected
DHTUDPPacketReplyFindNode( DHTUDPPacketNetworkHandler network_handler, InetSocketAddress originator, DataInputStream is, int trans_id )57 	DHTUDPPacketReplyFindNode(
58 		DHTUDPPacketNetworkHandler		network_handler,
59 		InetSocketAddress				originator,
60 		DataInputStream					is,
61 		int								trans_id )
62 
63 		throws IOException
64 	{
65 		super( network_handler, originator, is, DHTUDPPacketHelper.ACT_REPLY_FIND_NODE, trans_id );
66 
67 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ANTI_SPOOF ){
68 
69 			random_id	= is.readInt();
70 		}
71 
72 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_XFER_STATUS ){
73 
74 			node_status = is.readInt();
75 		}
76 
77 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_SIZE_ESTIMATE ){
78 
79 			estimated_dht_size	= is.readInt();
80 		}
81 
82 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_VIVALDI ){
83 
84 			DHTUDPUtils.deserialiseVivaldi( this, is );
85 		}
86 
87 		contacts = DHTUDPUtils.deserialiseContacts( getTransport(), is );
88 	}
89 
90 	public void
serialise( DataOutputStream os )91 	serialise(
92 		DataOutputStream	os )
93 
94 		throws IOException
95 	{
96 		super.serialise(os);
97 
98 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_ANTI_SPOOF ){
99 
100 			os.writeInt( random_id );
101 		}
102 
103 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_XFER_STATUS ){
104 
105 			 os.writeInt( node_status );
106 		}
107 
108 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_SIZE_ESTIMATE ){
109 
110 			 os.writeInt( estimated_dht_size );
111 		}
112 
113 		if ( getProtocolVersion() >= DHTTransportUDP.PROTOCOL_VERSION_VIVALDI ){
114 
115 			DHTUDPUtils.serialiseVivaldi( this, os );
116 		}
117 
118 		DHTUDPUtils.serialiseContacts( os, contacts );
119 	}
120 
121 	protected void
setContacts( DHTTransportContact[] _contacts )122 	setContacts(
123 		DHTTransportContact[]	_contacts )
124 	{
125 		contacts	= _contacts;
126 	}
127 
128 	protected void
setRandomID( int _random_id )129 	setRandomID(
130 		int	_random_id )
131 	{
132 		random_id	= _random_id;
133 	}
134 
135 	protected int
getRandomID()136 	getRandomID()
137 	{
138 		return( random_id );
139 	}
140 
141 	protected void
setNodeStatus( int ns )142 	setNodeStatus(
143 		int		ns )
144 	{
145 		node_status	= ns;
146 	}
147 
148 	protected int
getNodeStatus()149 	getNodeStatus()
150 	{
151 		return( node_status );
152 	}
153 
154 	protected void
setEstimatedDHTSize( int s )155 	setEstimatedDHTSize(
156 		int	s )
157 	{
158 		estimated_dht_size	= s;
159 	}
160 
161 	protected int
getEstimatedDHTSize()162 	getEstimatedDHTSize()
163 	{
164 		return( estimated_dht_size );
165 	}
166 
167 	protected DHTTransportContact[]
getContacts()168 	getContacts()
169 	{
170 		return( contacts );
171 	}
172 
173 	public String
getString()174 	getString()
175 	{
176 		return( super.getString() + ",contacts=" + (contacts==null?"null":(""+contacts.length )));
177 	}
178 }
179