[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r20803 - in gnunet-java: . src/org/gnunet/dht src/org/gnune
From: |
gnunet |
Subject: |
[GNUnet-SVN] r20803 - in gnunet-java: . src/org/gnunet/dht src/org/gnunet/util |
Date: |
Thu, 29 Mar 2012 13:52:18 +0200 |
Author: dold
Date: 2012-03-29 13:52:18 +0200 (Thu, 29 Mar 2012)
New Revision: 20803
Added:
gnunet-java/src/org/gnunet/util/Server.java
gnunet-java/src/org/gnunet/util/Service.java
Modified:
gnunet-java/ISSUES
gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
Log:
dht api finished
Modified: gnunet-java/ISSUES
===================================================================
--- gnunet-java/ISSUES 2012-03-28 19:35:54 UTC (rev 20802)
+++ gnunet-java/ISSUES 2012-03-29 11:52:18 UTC (rev 20803)
@@ -317,20 +317,29 @@
------------------------------------------------------------------------
-* gnunet-service-dht -h produces segfault
-* block type "any" does not work on request (gnunet-dht-get always changes any
to test)
-* SendMessage: comment on peer field ambiguous
-* should we support the TEST message, how should service_test be implemented?
-
* DHT:
+ * gnunet-service-dht -h produces segfault
+ * block type "any" does not work on request (gnunet-dht-get always changes
any to test)
* why is there no ack from the dht that a put request has been received?
* how unique is the UID? globally? per connection?
* by looking at the sources: (client,uid) identifies a request unambiguously
* what is a "dealy do"? ;) (see dht.h)
* why does the ClientGetStopMessage include the Hash? Isn't the 64-bit UID
sufficient?
-* advantages / disadvantages of queueing messages (in client and core)
+* GetOpt parser: currently no way of determining whether an option has been
set or is just on its default
+
+* Core:
+ * is the array of MessageHandlers really a good API? shouldn't we use the
runabout
+ and specify a set of GnunetMessage.Bodys that we are interested in?
+ * SendMessageRequest.queue_size?
+ * SendMessage: comment on peer field ambiguous
+ * why does SendMessageReady contain the peer?
+ * advantages / disadvantages of queueing messages (in client and core)
+
+* Server/Service API
+ *
+
* should I check in stuff like the installer binary etc.?
\ No newline at end of file
Modified: gnunet-java/src/org/gnunet/dht/DistributedHashTable.java
===================================================================
--- gnunet-java/src/org/gnunet/dht/DistributedHashTable.java 2012-03-28
19:35:54 UTC (rev 20802)
+++ gnunet-java/src/org/gnunet/dht/DistributedHashTable.java 2012-03-29
11:52:18 UTC (rev 20803)
@@ -151,7 +151,7 @@
@UInt32
public int reserved = 0;
@UInt64
- long unique_id;
+ public long unique_id;
@Nested
public HashCodeMessage key;
}
@@ -196,6 +196,7 @@
private Client client;
private long uid = 1;
+ private Configuration cfg;
/**
* Create a connection with the DHT service.
@@ -203,6 +204,7 @@
* @param cfg the configuration to use
*/
public DistributedHashTable(Configuration cfg) {
+ this.cfg = cfg;
client = new Client("dht", cfg);
}
@@ -249,6 +251,7 @@
public HashCode key;
public ResultCallback cb;
public AbsoluteTime deadline;
+ public boolean canceled = false;
public GetRequest() {
uid = DistributedHashTable.this.uid++;
@@ -259,6 +262,8 @@
throw new InterfaceViolationException("cancel called on
invalid request");
}
+ canceled = true;
+
activeRequests.remove(this);
if (activeRequests.isEmpty()) {
@@ -305,10 +310,6 @@
} else {
request.cb.handleResult(AbsoluteTime.fromNetwork(rm.expiration),
HashCode.fromMessage(rm.key), null, null,
BlockType.TEST, rm.data);
-
- if (request.deadline.isDue()) {
- request.cancel();
- }
}
if (!activeRequests.isEmpty()) {
@@ -321,20 +322,13 @@
}
}
-
- private AbsoluteTime earliestDeadline;
-
- private Scheduler.Task deadlineTask;
-
-
private final ResponseDispatcher rh = new ResponseDispatcher();
-
public Cancelable startGet(RelativeTime timeout, BlockType type, HashCode
key,
int replication, int routeOptions,
byte[] xquery, ResultCallback cb) {
- GetRequest request = new GetRequest();
+ final GetRequest request = new GetRequest();
request.key = key;
request.cb = cb;
request.deadline = timeout.toAbsolute();
@@ -347,11 +341,13 @@
getMessage.type = type.val;
getMessage.uniqueId = request.uid;
+
activeRequests.add(request);
if (receiveHandle == null) {
receiveHandle = client.receive(RelativeTime.FOREVER, rh);
}
+
client.notifyTransmitReady(timeout, false, new MessageTransmitter() {
@Override
public void transmit(Client.MessageSink sink) {
@@ -360,13 +356,34 @@
@Override
public void handleError(Client.TransmitError error) {
+ if (!request.canceled) {
+ request.cancel();
+ }
+ if (activeRequests.isEmpty()) {
+ client.disconnect();
+ }
}
});
+
+ Scheduler.add(new Scheduler.Task() {
+ @Override
+ public void run(Scheduler.RunContext ctx) {
+ logger.debug("timeout task has been run");
+ // maybe already canceled by notifyTransmitReady timeout
+ if (!request.canceled) {
+ request.cancel();
+ }
+ }
+ }, timeout);
return request;
}
+ public void destroy() {
+ client.disconnect();
+ }
+
public static void main(String[] args) {
new Program(args) {
@Option(action = OptionAction.SET,
@@ -413,23 +430,37 @@
return;
}
- DistributedHashTable dht = new DistributedHashTable(cfg);
+
if (modePut) {
if (data == null) {
System.out.println("data required on put");
return;
}
+ final DistributedHashTable dht = new
DistributedHashTable(cfg);
+
dht.put(new HashCode(key), data.getBytes(), replication,
EnumSet.of(RouteOption.NONE),
BlockType.TEST,
AbsoluteTime.now().add(RelativeTime.HOUR),
- RelativeTime.FOREVER, new Continuation() {
+ RelativeTime.SECOND, new Continuation() {
@Override
public void call(PutResult r) {
- System.out.println("put request sent");
+ if (r.equals(PutResult.OK)) {
+ System.out.println("put request sent");
+ } else {
+ System.out.println("timeout");
+ }
+ dht.destroy();
}
});
} else {
+ if (data != null) {
+ System.out.println("get does not taks data as an
option");
+ return;
+ }
+
+ final DistributedHashTable dht = new
DistributedHashTable(cfg);
+
dht.startGet(RelativeTime.SECOND, BlockType.TEST, new
HashCode(key), replication, 0,
new byte[0], new ResultCallback() {
@Override
Added: gnunet-java/src/org/gnunet/util/Server.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Server.java (rev 0)
+++ gnunet-java/src/org/gnunet/util/Server.java 2012-03-29 11:52:18 UTC (rev
20803)
@@ -0,0 +1,11 @@
+package org.gnunet.util;
+
+
+public class Server {
+ public class ClientHandle {
+ // ...
+ }
+ public Server(String serviceName, Configuration cfg) {
+
+ }
+}
Added: gnunet-java/src/org/gnunet/util/Service.java
===================================================================
--- gnunet-java/src/org/gnunet/util/Service.java
(rev 0)
+++ gnunet-java/src/org/gnunet/util/Service.java 2012-03-29 11:52:18 UTC
(rev 20803)
@@ -0,0 +1,29 @@
+package org.gnunet.util;
+
+
+public abstract class Service {
+ private Server s;
+
+ public Service(String[] args) {
+ // load configuration, parse args, ...
+ }
+
+ public final Server getServer() {
+ return s;
+
+ }
+
+
+ public final void start() {
+ // ...
+ }
+
+ public final void stop() {
+
+ }
+
+ /**
+ * Override to implement the behavior of the Program.
+ */
+ public abstract void run();
+}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r20803 - in gnunet-java: . src/org/gnunet/dht src/org/gnunet/util,
gnunet <=