Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: Freenet/message/DataReply.java


1   package Freenet.message;
2   import java.io.*;
3   import Freenet.*;
4   import Freenet.node.*;
5   import Freenet.support.*;
6   
7   /*
8     This code is part of the Java Adaptive Network Client by Ian Clarke. 
9     It is distributed under the GNU Public Licence (GPL) version 2.  See
10    http://www.gnu.org/ for further details of the GPL.
11  
12    Explanation of Code Versions: 
13      0.0.0      = Initial Description
14      0.0.1      = API Specified
15      0.x (x>0)  = Partial Implementation
16      x.0 (x>0)  = Operational
17      
18    Requires Classes: Node (1.0)
19                      Address (1.0)
20          Message (1.0)
21   */
22  
23  /**
24   * This is the DataReply message
25   *
26   * @see Node
27   * @see Address
28   * @author Brandon Wiley (blanu@uts.cc.utexas.edu)
29   * @author Ian Clarke (I.Clarke@strs.co.uk)
30   **/
31  
32  public class DataReply extends DataSend
33  {
34  
35      public static final String messageName = "DataReply";
36  
37    public DataReply(long idnum, long htl, long depth, Address dsrc)
38      {
39        super(idnum, htl, depth, dsrc);
40        keepAlive = false;
41      }
42  
43      public DataReply(long idnum, long htl, long depth, Address dsrc, Data data) throws IOException, DataNotReadyException{
44  
45    super(idnum, htl, depth, dsrc, data);
46    keepAlive = false;
47      }
48  
49    public DataReply(RawMessage raw) throws InvalidMessageException
50    {
51      super(raw);
52      keepAlive = false;
53    }
54  
55    public RawMessage toRawMessage()
56    {
57      RawMessage raw=super.toRawMessage();
58      raw.messageType="DataReply";
59      return raw;
60    }
61  
62      public void sending(Core n, Address peer, Address myAddress) throws SendFailedException
63      {
64    if (myAddress.equals(peer))
65        throw new SendFailedException(peer); // don't send to yourself
66    source = myAddress;
67  
68    // Set dataSource to my address if it is unknown, this message was never received, this message was received from a different network, or a random probability.
69    if ( dataSource == null || receivedAt == null || !receivedAt.equalsHost(myAddress) || ((new java.util.Random()).nextInt() % 30) == 0)
70        {
71      this.dataSource = myAddress;
72        }
73      }
74  
75        // Protected/Private Methods
76  
77      protected MessageMemory timeOut(Node n, MessageMemory sb)
78      {
79    if (sb == null || sb.depth <= 0) return null;
80  
81    TimedOut to=new TimedOut(id, sb.depth);
82      
83    try {
84        to.sendBack(n,sb);
85    } catch(SendFailedException sfe) {
86        Logger.log("DataReply.java","Send failed on timedout",Logger.NORMAL);
87    }
88  
89          return super.timeOut(n,sb);
90      }
91  }
92  
93