mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-04-07 11:08:36 +00:00
Add signing key to routing messages
This commit is contained in:
parent
d028818c0b
commit
a71c7ce698
@ -30,6 +30,7 @@ import java.util.HashSet;
|
||||
public class JSONTableScanner {
|
||||
|
||||
private static class Column {
|
||||
public boolean supported;
|
||||
public String label;
|
||||
public Class type;
|
||||
public JSONTokeniser.Narrow opts;
|
||||
@ -55,6 +56,7 @@ public class JSONTableScanner {
|
||||
col.label = label;
|
||||
col.type = type;
|
||||
col.opts = opts;
|
||||
col.supported = JSONTokeniser.supportsNarrowTo(col.type);
|
||||
columnMap.put(label, col);
|
||||
return this;
|
||||
}
|
||||
@ -91,7 +93,7 @@ public class JSONTableScanner {
|
||||
Column col = columns[i];
|
||||
if (col != null) {
|
||||
Object value;
|
||||
if (JSONTokeniser.supportsNarrowTo(col.type))
|
||||
if (col.supported)
|
||||
value = JSONTokeniser.narrow(row[i], col.type, col.opts);
|
||||
else {
|
||||
value = JSONTokeniser.narrow(row[i], col.opts);
|
||||
|
@ -22,12 +22,7 @@ package org.servalproject.servaldna;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
public class BundleId extends AbstractId {
|
||||
|
||||
@Override
|
||||
public int getBinarySize() {
|
||||
return 32;
|
||||
}
|
||||
public class BundleId extends SigningKey {
|
||||
|
||||
public BundleId(String hex) throws InvalidHexException {
|
||||
super(hex);
|
||||
|
@ -13,7 +13,10 @@ public class RouteLink {
|
||||
private static final int REACHABLE_UNICAST = (1<<2);
|
||||
//private static final int REACHABLE_INDIRECT = (1<<3);
|
||||
|
||||
public final Subscriber subscriber;
|
||||
@Deprecated
|
||||
public final SubscriberId sid;
|
||||
|
||||
public final SubscriberId next_hop;
|
||||
public final SubscriberId prior_hop;
|
||||
public final int hop_count;
|
||||
@ -34,7 +37,8 @@ public class RouteLink {
|
||||
}
|
||||
|
||||
RouteLink(ByteBuffer buff) throws AbstractId.InvalidBinaryException, BufferUnderflowException {
|
||||
sid = new SubscriberId(buff);
|
||||
this.subscriber = new Subscriber(buff);
|
||||
this.sid = subscriber.sid;
|
||||
reachable = 0xFF & (int)buff.get();
|
||||
int hop_count=-1;
|
||||
SubscriberId next_hop = null;
|
||||
@ -70,7 +74,7 @@ public class RouteLink {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RouteLink{" +
|
||||
"sid=" + sid +
|
||||
"subscriber=" + subscriber +
|
||||
", next_hop=" + next_hop +
|
||||
", prior_hop=" + prior_hop +
|
||||
", hop_count=" + hop_count +
|
||||
|
25
java/org/servalproject/servaldna/SigningKey.java
Normal file
25
java/org/servalproject/servaldna/SigningKey.java
Normal file
@ -0,0 +1,25 @@
|
||||
package org.servalproject.servaldna;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Created by jeremy on 22/06/16.
|
||||
*/
|
||||
public class SigningKey extends AbstractId {
|
||||
public SigningKey(String hex) throws InvalidHexException {
|
||||
super(hex);
|
||||
}
|
||||
|
||||
public SigningKey(ByteBuffer b) throws InvalidBinaryException {
|
||||
super(b);
|
||||
}
|
||||
|
||||
public SigningKey(byte[] binary) throws InvalidBinaryException {
|
||||
super(binary);
|
||||
}
|
||||
|
||||
@Override
|
||||
int getBinarySize() {
|
||||
return 32;
|
||||
}
|
||||
}
|
53
java/org/servalproject/servaldna/Subscriber.java
Normal file
53
java/org/servalproject/servaldna/Subscriber.java
Normal file
@ -0,0 +1,53 @@
|
||||
package org.servalproject.servaldna;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Created by jeremy on 22/06/16.
|
||||
*/
|
||||
public final class Subscriber {
|
||||
public final SubscriberId sid;
|
||||
public final SigningKey signingKey;
|
||||
public final boolean combined;
|
||||
|
||||
public Subscriber(SubscriberId sid){
|
||||
this(sid, null, false);
|
||||
}
|
||||
|
||||
public Subscriber(SubscriberId sid, SigningKey signingKey, boolean combined){
|
||||
this.sid = sid;
|
||||
this.signingKey = signingKey;
|
||||
this.combined = combined;
|
||||
}
|
||||
|
||||
public Subscriber(ByteBuffer buff) throws AbstractId.InvalidBinaryException {
|
||||
SubscriberId sid = new SubscriberId(buff);
|
||||
SigningKey signingKey = new SigningKey(buff);
|
||||
int signKeyFlags = 0xFF & (int)buff.get();
|
||||
if ((signKeyFlags&0x01)==0x00)
|
||||
signingKey = null;
|
||||
this.sid = sid;
|
||||
this.signingKey = signingKey;
|
||||
this.combined = (signKeyFlags&0x02)==0x02;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Subscriber that = (Subscriber) o;
|
||||
|
||||
return sid.equals(that.sid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return sid.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString(){
|
||||
return sid.toString();
|
||||
}
|
||||
}
|
@ -497,6 +497,12 @@ static int app_route_print(const struct cli_parsed *parsed, struct cli_context *
|
||||
sid_t *sid = (sid_t *)ob_get_bytes_ptr(buff, SID_SIZE);
|
||||
if (!sid)
|
||||
break;
|
||||
|
||||
// ignore signing key details for now
|
||||
ob_skip(buff, SAS_SIZE+1);
|
||||
if (ob_overrun(buff))
|
||||
break;
|
||||
|
||||
int reachable = ob_get(buff);
|
||||
if (reachable<0)
|
||||
break;
|
||||
|
@ -1068,6 +1068,8 @@ static void send_route(struct subscriber *subscriber, struct socket_address *cli
|
||||
struct overlay_buffer *b = ob_static(payload, sizeof payload);
|
||||
ob_limitsize(b, sizeof payload);
|
||||
ob_append_bytes(b, subscriber->sid.binary, SID_SIZE);
|
||||
ob_append_bytes(b, subscriber->sas_public, SAS_SIZE);
|
||||
ob_append_byte(b, subscriber->sas_valid | (subscriber->sas_combined<<1));
|
||||
ob_append_byte(b, subscriber->reachable);
|
||||
if (subscriber->reachable & REACHABLE){
|
||||
ob_append_byte(b, subscriber->hop_count);
|
||||
|
Loading…
x
Reference in New Issue
Block a user