aboutsummaryrefslogtreecommitdiff
path: root/src/org/gnunet/mesh/Mesh.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/gnunet/mesh/Mesh.java')
-rw-r--r--src/org/gnunet/mesh/Mesh.java158
1 files changed, 143 insertions, 15 deletions
diff --git a/src/org/gnunet/mesh/Mesh.java b/src/org/gnunet/mesh/Mesh.java
index d739b61..4b43c97 100644
--- a/src/org/gnunet/mesh/Mesh.java
+++ b/src/org/gnunet/mesh/Mesh.java
@@ -25,36 +25,122 @@ import org.gnunet.requests.RequestQueue;
25import org.gnunet.util.*; 25import org.gnunet.util.*;
26import org.grothoff.Runabout; 26import org.grothoff.Runabout;
27 27
28import java.util.List;
29
30/** 28/**
29 *
30 *
31 * @author Florian Dold 31 * @author Florian Dold
32 */ 32 */
33public class Mesh { 33public class Mesh {
34 private RequestQueue requestQueue; 34 private RequestQueue requestQueue;
35 private TunnelEndHandler tunnelEndHandler; 35 private TunnelEndHandler tunnelEndHandler;
36 private Runabout messageReceiver; 36 private Runabout messageReceiver;
37 private List<Integer> applications; 37 private int[] applications;
38 private InboundTunnelHandler inboundTunnelHandler; 38 private InboundTunnelHandler inboundTunnelHandler;
39 39
40 40
41 public static class RootTunnel { 41 private int nextTunnelId = 0x80000000;
42 int tunnel_id; 42
43
44 public class RootTunnel extends Tunnel {
43 public void addPeer(PeerIdentity peerIdentity) { 45 public void addPeer(PeerIdentity peerIdentity) {
44 46
45 } 47 }
48 /**
49 * Request that the given peer isn't added to this tunnel in calls to
50 * connect_by_* calls, (due to misbehaviour, bad performance, ...).
51 *
52 * @param peerIdentity peer identity of the peer which should be blacklisted
53 * for the tunnel.
54 */
46 public void blacklist(PeerIdentity peerIdentity) { 55 public void blacklist(PeerIdentity peerIdentity) {
47 56
48 } 57 }
49 public void destroy() { 58 /**
50 // ... 59 * Request that the given peer isn't blacklisted anymore from this tunnel,
60 * and therefore can be added in future calls to connect*.
61 * The peer must have been previously blacklisted for this tunnel.
62 *
63 * @param peerIdentity peer identity of the peer which shouldn't be blacklisted
64 * for the tunnel anymore.
65 */
66 public void unblacklist(PeerIdentity peerIdentity) {
67
68 }
69 /**
70 * Request that the mesh should try to connect to a peer supporting the given
71 * message type.
72 *
73 * @param appType application type that must be supported by the peer
74 * (MESH should discover peer in proximity handling this type)
75 */
76 public void requestConnectByType (int appType) {
77
78 }
79
80 /**
81 * Request that the mesh should try to connect to a peer matching the
82 * description given in the service string.
83 *
84 * @param description string describing the destination node requirements
85 */
86 public void requestConnectByType (String description) {
87
88 }
89
90 /**
91 * Request that a peer should be added to the tunnel. The connect handler
92 * will be called when the peer connects
93 *
94 * @param peer peer to add
95 */
96 public void requestConnectAdd (PeerIdentity peer) {
97
98 }
99
100 /**
101 * Request that a peer should be removed from the tunnel. The existing
102 * disconnect handler will be called ONCE if we were connected.
103 *
104 * @param peer peer to remove
105 */
106 public void requestConnectDel (PeerIdentity peer) {
107
108 }
109
110 private void registerWithService() {
111 requestQueue.add(new TunnelCreateRequest(this));
51 } 112 }
52 } 113 }
53 114
54 public static class Tunnel extends RootTunnel { 115 public class Tunnel {
55 public Cancelable notifyTransmitReady(PeerIdentity target) { 116 int tunnel_id;
117
118 /**
119 * Ask the mesh to call "notify" once it is ready to transmit the
120 * given number of bytes to the specified tunnel or target.
121 * Only one call can be active at any time, to issue another request,
122 * wait for the callback or cancel the current request.
123 *
124 * @param maxdelay how long can the message wait?
125 * @param target destination for the message
126 * NULL for multicast to all tunnel targets
127 * @param notify_size how many bytes of buffer space does notify want?
128 * @param transmitter handler to call when buffer space is available;
129 * will be called with NULL on timeout or if the overall queue
130 * for this peer is larger than queue_size and this is currently
131 * the message with the lowest priority
132 * @return non-NULL if the notify callback was queued,
133 * NULL if we can not even queue the request (insufficient
134 * memory); if NULL is returned, "notify" will NOT be called.
135 */
136 public Cancelable notifyTransmitReady(RelativeTime maxdelay, PeerIdentity target, int notify_size, MessageTransmitter transmitter) {
56 return null; 137 return null;
57 } 138 }
139
140 public void destroy() {
141 // ...
142 }
143
58 } 144 }
59 145
60 146
@@ -62,7 +148,28 @@ public class Mesh {
62 148
63 @Override 149 @Override
64 public void transmit(Connection.MessageSink sink) { 150 public void transmit(Connection.MessageSink sink) {
65 //To change body of implemented methods use File | Settings | File Templates. 151 ClientConnectMessage ccm = new ClientConnectMessage();
152 ccm.applications_length = applications.length;
153 ccm.apps_list = applications;
154 int[] types = RunaboutUtil.getRunaboutMessageTypes(messageReceiver);
155 ccm.types_list = types;
156 ccm.types_length = types.length;
157 sink.send(ccm);
158 }
159 }
160
161 public class TunnelCreateRequest extends Request {
162 public RootTunnel tunnel;
163
164 public TunnelCreateRequest(RootTunnel rootTunnel) {
165 tunnel = rootTunnel;
166 }
167
168 @Override
169 public void transmit(Connection.MessageSink sink) {
170 TunnelCreateMessage tcm = new TunnelCreateMessage();
171 tcm.tunnel_id = tunnel.tunnel_id;
172 sink.send(tcm);
66 } 173 }
67 } 174 }
68 175
@@ -76,7 +183,7 @@ public class Mesh {
76 183
77 184
78 public Mesh(Configuration cfg, InboundTunnelHandler inboundTunnelHandler, 185 public Mesh(Configuration cfg, InboundTunnelHandler inboundTunnelHandler,
79 TunnelEndHandler tunnelEndHandler, Runabout messageReceiver, List<Integer> applications) { 186 TunnelEndHandler tunnelEndHandler, Runabout messageReceiver, int... applications) {
80 this.tunnelEndHandler = tunnelEndHandler; 187 this.tunnelEndHandler = tunnelEndHandler;
81 this.messageReceiver = messageReceiver; 188 this.messageReceiver = messageReceiver;
82 this.applications = applications; 189 this.applications = applications;
@@ -86,17 +193,38 @@ public class Mesh {
86 requestQueue = new RequestQueue(client, new MeshMessageReceiver()); 193 requestQueue = new RequestQueue(client, new MeshMessageReceiver());
87 194
88 requestQueue.add(new ClientConnectRequest()); 195 requestQueue.add(new ClientConnectRequest());
89
90 } 196 }
91 197
92 /** 198 /**
93 * Create a new tunnel (we're initiator and will be allowed to add/remove peers 199 * Create a new tunnel (we're initiator and will be allowed to add/remove peers
94 * and to broadcast). 200 * and to broadcast).
201 *
202 * @param connectHandler function to call when peers are actually connected
203 * @param disconnectHandler function to call when peers are disconnected
95 */ 204 */
96 public RootTunnel createTunnel(/* ... */) { 205 public RootTunnel createTunnel(ConnectHandler connectHandler, DisconnectHandler disconnectHandler) {
97 return null; 206 RootTunnel tunnel = new RootTunnel();
207 tunnel.tunnel_id = nextTunnelId++;
208 tunnel.registerWithService();
209 return tunnel;
98 } 210 }
99 211
212
213 /**
214 * Announce to ther peer the availability of services described by the regex,
215 * in order to be reachable to other peers via connect_by_string.
216 *
217 * Note that the first 8 characters are considered to be part of a prefix,
218 * (for instance 'gnunet://'). If you put a variable part in there (*, +. ()),
219 * all matching strings will be stored in the DHT.
220 *
221 * @param regex string with the regular expression describing local services.
222 */
223 public void announceRegex(String regex) {
224
225 }
226
227
100 /** 228 /**
101 * Disconnect from the mesh service. All tunnels will be destroyed. All tunnel 229 * Disconnect from the mesh service. All tunnels will be destroyed. All tunnel
102 * disconnect callbacks will be called on any still connected peers, notifying 230 * disconnect callbacks will be called on any still connected peers, notifying
@@ -104,6 +232,6 @@ public class Mesh {
104 * called should any inbound tunnels still exist. 232 * called should any inbound tunnels still exist.
105 */ 233 */
106 public void disconnect() { 234 public void disconnect() {
107 235 requestQueue.destroy();
108 } 236 }
109} 237}