public void HandleRpc(ISender caller, string method, IList args, object rs) {
object result = null;
try {
if(method.Equals("Put")) {
MemBlock key = (byte[]) args[0];
MemBlock value = (byte[]) args[1];
int ttl = (int) args[2];
bool unique = (bool) args[3];
Put(key, value, ttl, unique, rs);
return;
}
else if(method.Equals("PutHandler")) {
MemBlock key = (byte[]) args[0];
MemBlock value = (byte[]) args[1];
int ttl = (int) args[2];
bool unique = (bool) args[3];
result = PutHandler(key, value, ttl, unique);
}
else if(method.Equals("Get")) {
MemBlock key = (byte[]) args[0];
// Hack for backwards compatibility, supports forwards too
int token_pos = args.Count - 1;
if(args[token_pos] == null) {
result = Get(key, null);
}
else {
result = Get(key, (byte[]) args[token_pos]);
}
}
else if(method.Equals("Dump")) {
lock(_sync) {
result = _data.Dump();
}
}
else if(method.Equals("Count")) {
result = Count;
}
else {
throw new Exception("Dht.Exception: Invalid method");
}
}
catch (Exception e) {
result = new AdrException(-32602, e);
}
_rpc.SendResult(rs, result);
}