diff options
Diffstat (limited to 'src/main/java/org/gnunet/transport/Transport.java')
-rw-r--r-- | src/main/java/org/gnunet/transport/Transport.java | 156 |
1 files changed, 156 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/transport/Transport.java b/src/main/java/org/gnunet/transport/Transport.java new file mode 100644 index 0000000..b9881b6 --- /dev/null +++ b/src/main/java/org/gnunet/transport/Transport.java | |||
@@ -0,0 +1,156 @@ | |||
1 | package org.gnunet.transport; | ||
2 | |||
3 | import org.gnunet.hello.HelloMessage; | ||
4 | import org.gnunet.mq.Envelope; | ||
5 | import org.gnunet.mq.NotifySentHandler; | ||
6 | import org.gnunet.util.*; | ||
7 | |||
8 | /** | ||
9 | * ... | ||
10 | * | ||
11 | * @author Florian Dold | ||
12 | */ | ||
13 | public class Transport { | ||
14 | |||
15 | /** | ||
16 | * Client that connects to the transport service, | ||
17 | */ | ||
18 | private final Client client; | ||
19 | |||
20 | boolean init_requested; | ||
21 | |||
22 | /** | ||
23 | * Blacklist callback, null if there is no active blacklist | ||
24 | * for this handle. | ||
25 | */ | ||
26 | BlacklistCallback blacklistCallback; | ||
27 | |||
28 | private final class TransportReceiver extends RunaboutMessageReceiver { | ||
29 | @Override | ||
30 | public void handleError() { | ||
31 | client.reconnect(); | ||
32 | // FIXME: complete | ||
33 | } | ||
34 | } | ||
35 | |||
36 | /** | ||
37 | * Create a handle to the transport service. | ||
38 | * | ||
39 | * @param cfg configuration to use for connecting | ||
40 | */ | ||
41 | public Transport(Configuration cfg) { | ||
42 | client = new Client("transport", cfg); | ||
43 | client.installReceiver(new TransportReceiver()); | ||
44 | } | ||
45 | |||
46 | /** | ||
47 | * Ask the transport service to establish a connection to | ||
48 | * the given peer. | ||
49 | * | ||
50 | * @param target who we should try to connect to | ||
51 | * @param cb callback to be called when request was transmitted to transport | ||
52 | * service | ||
53 | * @return a handle to cancel the operation | ||
54 | */ | ||
55 | Cancelable tryConnect(PeerIdentity target, final TryConnectCallback cb) { | ||
56 | RequestConnectMessage m = new RequestConnectMessage(); | ||
57 | m.peer = target; | ||
58 | m.reserved = 0; | ||
59 | final Envelope ev = new Envelope(m); | ||
60 | ev.notifySent(new NotifySentHandler() { | ||
61 | @Override | ||
62 | public void onSent() { | ||
63 | cb.onDone(); | ||
64 | } | ||
65 | }); | ||
66 | client.send(ev); | ||
67 | |||
68 | return new Cancelable() { | ||
69 | @Override | ||
70 | public void cancel() { | ||
71 | ev.cancel(); | ||
72 | } | ||
73 | }; | ||
74 | } | ||
75 | |||
76 | /** | ||
77 | * ... (discuss first) | ||
78 | */ | ||
79 | public void init(Object receiveCallback, Object notifyConnect, Object notifyDisconnect) { | ||
80 | |||
81 | } | ||
82 | |||
83 | |||
84 | /** | ||
85 | * Obtain the HELLO message for this peer. | ||
86 | * | ||
87 | * @param rec function to call with the HELLO, sender will be our peer | ||
88 | * identity; message and sender will be NULL on timeout | ||
89 | * (handshake with transport service pending/failed). | ||
90 | * cost estimate will be 0. | ||
91 | * @return handle to cancel the operation | ||
92 | */ | ||
93 | Cancelable getHello(HelloUpdateCallback rec) { | ||
94 | throw new UnsupportedOperationException(); | ||
95 | } | ||
96 | |||
97 | /** | ||
98 | * Offer the transport service the HELLO of another peer. Note that | ||
99 | * the transport service may just ignore this message if the HELLO is | ||
100 | * malformed or useless due to our local configuration. | ||
101 | * | ||
102 | * @param hello the hello message | ||
103 | * @param cont continuation to call when HELLO has been sent, | ||
104 | * tc reason GNUNET_SCHEDULER_REASON_TIMEOUT for fail | ||
105 | * tc reasong GNUNET_SCHEDULER_REASON_READ_READY for success | ||
106 | * @return a GNUNET_TRANSPORT_OfferHelloHandle handle or NULL on failure, | ||
107 | * in case of failure cont will not be called | ||
108 | */ | ||
109 | |||
110 | Cancelable offerHello(HelloMessage hello, | ||
111 | Scheduler.Task cont) { | ||
112 | throw new UnsupportedOperationException(); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * Install a blacklist callback. The service will be queried for all | ||
117 | * existing connections as well as any fresh connections to check if | ||
118 | * they are permitted. | ||
119 | * The blacklist is active until the Transport handle is destroyed. | ||
120 | * When the transport handle that installed the blacklist is destroyed, | ||
121 | * all hosts that were denied in the past will automatically be | ||
122 | * whitelisted again. This is the only way to re-enable | ||
123 | * connections from peers that were previously blacklisted. | ||
124 | * | ||
125 | * @param blacklistCallback callback to invoke to check if connections are allowed | ||
126 | */ | ||
127 | public void blacklist(BlacklistCallback blacklistCallback) { | ||
128 | if (this.blacklistCallback != null) | ||
129 | throw new AssertionError("there is already a blacklist"); | ||
130 | if (blacklistCallback == null) | ||
131 | throw new AssertionError("blacklist callback may not be null"); | ||
132 | this.blacklistCallback = blacklistCallback; | ||
133 | client.send(new BlacklistInitMessage()); | ||
134 | } | ||
135 | |||
136 | /** | ||
137 | * Return all the known addresses for a specific peer or all peers. | ||
138 | * Returns continuously all address if one_shot is set to false | ||
139 | * <p/> | ||
140 | * Returns the address(es) that we are currently using for this | ||
141 | * peer. Upon completion, the 'AddressLookUpCallback' is called one more | ||
142 | * time with 'NULL' for the address and the peer. After this, the operation must no | ||
143 | * longer be explicitly canceled. | ||
144 | * | ||
145 | * @param peer peer identity to look up the addresses of, CHANGE: allow NULL for all (connected) peers | ||
146 | * @param one_shot GNUNET_YES to return the current state and then end (with NULL+NULL), | ||
147 | * GNUNET_NO to monitor the set of addresses used (continuously, must be explicitly canceled) | ||
148 | * @param timeout how long is the lookup allowed to take at most (irrelevant if one_shot is set to GNUNET_NO) | ||
149 | * @param peer_address_callback function to call with the results | ||
150 | */ | ||
151 | Cancelable getActiveAddresses(PeerIdentity peer, int one_shot, | ||
152 | RelativeTime timeout, PeerIterateCallback peer_address_callback) { | ||
153 | throw new UnsupportedOperationException(); | ||
154 | } | ||
155 | } | ||
156 | |||