aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/org/gnunet/peerstore/WatchRequest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/org/gnunet/peerstore/WatchRequest.java')
-rw-r--r--src/main/java/org/gnunet/peerstore/WatchRequest.java77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/main/java/org/gnunet/peerstore/WatchRequest.java b/src/main/java/org/gnunet/peerstore/WatchRequest.java
new file mode 100644
index 0000000..4460c1c
--- /dev/null
+++ b/src/main/java/org/gnunet/peerstore/WatchRequest.java
@@ -0,0 +1,77 @@
1/*
2 This file is part of GNUnet.
3 (C) 2011, 2012 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20
21package org.gnunet.peerstore;
22
23import java.nio.ByteBuffer;
24
25import org.gnunet.mq.Envelope;
26import org.gnunet.peerstore.messages.WatchMessage;
27import org.gnunet.requests.Request;
28import org.gnunet.util.HashCode;
29import org.gnunet.util.PeerIdentity;
30
31class WatchRequest extends Request {
32 public final String sub_system;
33 public final PeerIdentity peer;
34 public final String key;
35 public final PeerstoreWatcher watcher;
36 public final HashCode hash;
37
38 public static HashCode getHash(String sub_system, PeerIdentity peer,
39 String key) {
40 int block_size = 0;
41 block_size += sub_system.length() + 1;
42 block_size += peer.data.length;
43 block_size += key.length() + 1;
44
45 byte[] block = new byte[block_size];
46 ByteBuffer target = ByteBuffer.wrap(block);
47 target.put(sub_system.getBytes());
48 target.put((byte)'\0');
49 target.put(peer.data);
50 target.put(key.getBytes());
51 target.put((byte)'\0');
52
53 return HashCode.hash(block);
54 }
55
56 public WatchRequest(String sub_system, PeerIdentity peer, String key,
57 PeerstoreWatcher watcher) {
58 this.sub_system = sub_system;
59 this.peer = peer;
60 this.key = key;
61 this.watcher = watcher;
62 this.hash = WatchRequest.getHash(sub_system, peer, key);
63 }
64
65 @Override
66 public Envelope assembleRequest() {
67 WatchMessage wm = new WatchMessage();
68 wm.keyhash = this.hash;
69 return new Envelope(wm);
70 }
71
72 @Override
73 public void cancel() {
74 // TODO: send a watch cancel request
75 }
76
77}