Source code: Freenet/message/DataRequest.java
1 /*
2 *$Id: DataRequest.java,v 1.26 2000/04/07 20:34:09 hobbex Exp $
3
4 This code is part of the Java Adaptive Network Client by Ian Clarke.
5 It is distributed under the GNU Public Licence (GPL) version 2. See
6 http://www.gnu.org/ for further details of the GPL.
7
8 Explanation of Code Versions:
9 0.0.0 = Initial Description
10 0.0.1 = API Specified
11 0.x (x>0) = Partial Implementation
12 x.0 (x>0) = Operational
13
14 Requires Classes: Node (1.0)
15 Address (1.0)
16 Message (1.0)
17 */
18
19 /**
20 * This is the DataRequest message
21 *
22 * @see Node
23 * @see Address
24 * @author Brandon Wiley (blanu@uts.cc.utexas.edu)
25 * @author Ian Clarke (I.Clarke@strs.co.uk)
26 **/
27
28 package Freenet.message;
29 import Freenet.*;
30 import Freenet.node.*;
31 import Freenet.support.*;
32 import java.util.Random;
33
34 public class DataRequest extends Request
35 {
36
37 public static final String messageName = "DataRequest";
38
39 public DataRequest(long idnum, long htl, long depth, Key key)
40 {
41 super(idnum, htl, depth, key);
42 }
43
44 public DataRequest(RawMessage raw) throws InvalidMessageException
45 {
46 super(raw);
47 }
48
49 public RawMessage toRawMessage()
50 {
51 RawMessage raw=super.toRawMessage();
52 raw.messageType="DataRequest";
53 return raw;
54 }
55
56 protected void refFound(Address ref, Node n) throws Request.RequestAbortException {} // request don't do anything about found refs.
57
58 protected void dataFound(Data data, Node n) throws Request.RequestAbortException {
59 Logger.log("message/DataRequest.java","Found " + searchKey + " replying",Logger.MINOR);
60 Random r = new Random(); // used to create random starting depth, so it isn't obvious the reply was stored here
61 DataReply drm=null;
62 try {
63 drm=new DataReply(id,
64 depth,
65 (long)(Math.abs(r.nextInt() % 200)),
66 null,
67 data);
68 } catch(Exception e) {
69 Logger.log("message/DataRequest.java","Error loading "+searchKey+" from DataStore: "+e,Logger.ERROR);
70 return;
71 }
72
73 try {
74 sendReply(n,drm);
75 } catch(SendFailedException sfe) {
76 Logger.log("message/DataRequest.java","Error sending DataReply to " + sfe.peer,Logger.NORMAL) ;
77 }
78 throw new Request.RequestAbortException(null); // My job is done. Abort and forget about this.
79 }
80 }
81
82
83
84 /*
85 *$Log: DataRequest.java,v $
86 *Revision 1.26 2000/04/07 20:34:09 hobbex
87 *Fixed building and running with Kaffe (scripts/kbuild.sh). Added canceling of timer callback and sending of requestfailed on loosing MessageMemory (not too well tested). And fixed a bug in the datastore + some exception catching in requestfailed.
88 *
89 *Revision 1.25 2000/04/05 22:14:08 hobbex
90 *Unknown message fields are passed, and source is now optional for clients
91 *
92 *Revision 1.24 2000/03/30 11:32:27 hobbex
93 *Close connections after sending KeepAlive=false message
94 *
95 *Revision 1.23 2000/03/29 18:49:14 hobbex
96 *Subclassed Node from Core, added Freenet.node package
97 *
98 *Revision 1.22 2000/03/27 21:02:32 hobbex
99 *Sustained streams
100 *
101 *Revision 1.21 2000/03/06 10:00:32 hobbex
102 *Large change to the way Inserts are handled. The chain is now InsertRequest->InsertReply->DataInsert.
103 *
104 *Revision 1.20 2000/02/29 06:47:31 blanu
105 *Fixed DataRequest not generating DataLength field in DataReply.
106 *
107 *Revision 1.19 2000/02/23 20:52:42 blanu
108 *Fixed timeout in client.
109 *
110 *Revision 1.18 2000/02/20 03:22:39 blanu
111 *Connections now timeout after connectTimeout milliseconds, as per the config file.
112 *
113 *Revision 1.17 2000/02/13 21:11:01 hobbex
114 *removed searchKey field from DataReply
115 *
116 *Revision 1.16 2000/02/13 14:06:27 sanity
117 *Changed so that timeouts always start with a timeout of 256 to ensure that
118 *they reach their destination.
119 *
120 *Revision 1.15 2000/02/08 14:24:30 hobbex
121 *Added timeout and restart on no reply functionality to requests
122 *
123 *Revision 1.14 2000/02/02 15:58:57 sanity
124 *Changed Freenet client so that keys are now hashed!
125 *
126 *Revision 1.13 2000/01/31 13:22:50 hobbex
127 *Changed the method for setting the DataSource in replies, and added a couple more get mthods to the connection
128 *
129 *Revision 1.12 2000/01/27 15:45:39 sanity
130 *Some bug fixes, added localAddress field to Node.java which is used by
131 *DataRequest and DataReply messages to set dataSource field. Also removed
132 *untidy debugging stuff from RawMessage.
133 *
134 *Revision 1.11 2000/01/27 10:01:11 sanity
135 *Added "origin" field to DataReply which stores either the node where the
136 *data originated, or a node closer to where the data originated. This is
137 *the functionality as described in the Freenet report.
138 *
139 *Revision 1.10 2000/01/27 00:52:34 hobbex
140 *Added backtracking InsertFailed messages
141 *
142 *Revision 1.9 2000/01/19 15:12:21 hobbex
143 *Fixed handeling of bad node addresses (SendFailedException)
144 *
145 *Revision 1.8 2000/01/11 01:01:46 hobbex
146 *added Depth field to all messages for setting hopsToLive of replies
147 *
148 *Revision 1.7 2000/01/10 21:54:46 hobbex
149 *Fixed timeout of Requests, all messages sent as a result of a Request now inherit the HTL of the original
150 *
151 *Revision 1.6 2000/01/09 18:46:41 hobbex
152 *Fixed setting of source field on multihomed nodes - I hope
153 *
154 *Revision 1.5 2000/01/06 01:04:50 hobbex
155 *Don't forward Inserts and Reuqests to self or source, don't accept inserts if key is known, and added an Address.equals method
156 *
157 *Revision 1.4 2000/01/03 10:20:48 hobbex
158 *Removed deleting of MM on Loop and Failed Request
159 *
160 *Revision 1.3 2000/01/02 19:10:49 michaels
161 *Reverted last change - has to be discussed first
162 *
163 *Revision 1.2 2000/01/02 14:30:04 michaels
164 *On a loop pReceived returns sb not null - seems to work, don't know
165 *about sideeffects
166 *
167 */
168
169
170
171