mirror of
https://github.com/servalproject/serval-dna.git
synced 2024-12-18 12:56:29 +00:00
Add MDP_INTERFACE_PEER for external unicast peer discovery to trigger a probe
This commit is contained in:
parent
0043e20b81
commit
c2103e3b86
@ -51,6 +51,7 @@ public abstract class AbstractExternalInterface extends ChannelSelector.Handler
|
||||
private static final int MDP_INTERFACE_UP=0;
|
||||
private static final int MDP_INTERFACE_DOWN=1;
|
||||
private static final int MDP_INTERFACE_RECV=2;
|
||||
private static final int MDP_INTERFACE_PEER=3;
|
||||
|
||||
public void up(String config) throws IOException {
|
||||
MdpPacket packet = new MdpPacket();
|
||||
@ -71,16 +72,12 @@ public abstract class AbstractExternalInterface extends ChannelSelector.Handler
|
||||
packet.send((DatagramChannel) socket.getChannel());
|
||||
}
|
||||
|
||||
public void receivedPacket(byte recvaddr[], byte recvbytes[]) throws IOException {
|
||||
receivedPacket(recvaddr, recvbytes, 0, recvbytes==null?0:recvbytes.length);
|
||||
}
|
||||
public void receivedPacket(byte recvaddr[], byte recvbytes[], int offset, int len) throws IOException {
|
||||
private void deliverPacket(int type, byte recvaddr[], byte recvbytes[], int offset, int len) throws IOException{
|
||||
if (!isUp)
|
||||
return;
|
||||
|
||||
MdpPacket packet = new MdpPacket();
|
||||
packet.setRemotePort(MDP_INTERFACE);
|
||||
packet.payload.put((byte) MDP_INTERFACE_RECV);
|
||||
packet.payload.put((byte) type);
|
||||
packet.payload.put((byte) recvaddr.length);
|
||||
packet.payload.put(recvaddr);
|
||||
if (len>0)
|
||||
@ -89,6 +86,17 @@ public abstract class AbstractExternalInterface extends ChannelSelector.Handler
|
||||
packet.send((DatagramChannel) socket.getChannel());
|
||||
}
|
||||
|
||||
public void discovered(byte recvaddr[]) throws IOException{
|
||||
deliverPacket(MDP_INTERFACE_PEER, recvaddr, null, 0, 0);
|
||||
}
|
||||
|
||||
public void receivedPacket(byte recvaddr[], byte recvbytes[]) throws IOException {
|
||||
deliverPacket(MDP_INTERFACE_RECV, recvaddr, recvbytes, 0, recvbytes==null?0:recvbytes.length);
|
||||
}
|
||||
public void receivedPacket(byte recvaddr[], byte recvbytes[], int offset, int len) throws IOException {
|
||||
deliverPacket(MDP_INTERFACE_RECV, recvaddr, recvbytes, offset, len);
|
||||
}
|
||||
|
||||
protected abstract void sendPacket(byte addr[], ByteBuffer payload);
|
||||
|
||||
@Override
|
||||
|
@ -51,8 +51,7 @@ public class MdpSocket{
|
||||
this.loopbackMdpPort = loopbackMdpPort;
|
||||
}
|
||||
public MdpSocket(int loopbackMdpPort, int port) throws IOException {
|
||||
this(loopbackMdpPort);
|
||||
bind(SubscriberId.ANY, port);
|
||||
this(loopbackMdpPort, SubscriberId.ANY, port);
|
||||
}
|
||||
public MdpSocket(int loopbackMdpPort, SubscriberId sid, int port) throws IOException {
|
||||
this(loopbackMdpPort);
|
||||
|
@ -99,6 +99,7 @@ struct mdp_identity_request {
|
||||
#define MDP_INTERFACE_UP 0
|
||||
#define MDP_INTERFACE_DOWN 1
|
||||
#define MDP_INTERFACE_RECV 2
|
||||
#define MDP_INTERFACE_PEER 3
|
||||
|
||||
#define MDP_ROUTE_TABLE 5
|
||||
|
||||
|
@ -1427,13 +1427,35 @@ static void mdp_interface_packet(struct socket_address *client, struct mdp_heade
|
||||
if (interface)
|
||||
overlay_interface_close(interface);
|
||||
}break;
|
||||
case MDP_INTERFACE_PEER:{
|
||||
// some form of external peer discovery has occurred
|
||||
struct overlay_interface *interface=overlay_interface_find_name_file_addr(NULL, NULL, client);
|
||||
if (interface){
|
||||
// queue a unicast probe packet to this address
|
||||
struct socket_address addr;
|
||||
addr.addrlen = ob_get(payload);
|
||||
if ((size_t)addr.addrlen > sizeof(addr)){
|
||||
WARNF("Malformed MDP_INTERFACE_RECV header, %u bytes is too large", (unsigned)addr.addrlen);
|
||||
break;
|
||||
}
|
||||
bcopy(ob_get_bytes_ptr(payload, addr.addrlen), addr.raw, addr.addrlen);
|
||||
struct network_destination *destination = create_unicast_destination(&addr, state->interface);
|
||||
if (!destination)
|
||||
break;
|
||||
overlay_send_probe(NULL, destination, OQ_ORDINARY);
|
||||
release_destination_ref(destination);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case MDP_INTERFACE_RECV:{
|
||||
struct overlay_interface *interface=overlay_interface_find_name_file_addr(NULL, NULL, client);
|
||||
if (interface){
|
||||
struct socket_address addr;
|
||||
addr.addrlen = ob_get(payload);
|
||||
if ((size_t)addr.addrlen > sizeof(addr))
|
||||
break; // TODO errors
|
||||
if ((size_t)addr.addrlen > sizeof(addr)){
|
||||
WARNF("Malformed MDP_INTERFACE_RECV header, %u bytes is too large", (unsigned)addr.addrlen);
|
||||
break;
|
||||
}
|
||||
bcopy(ob_get_bytes_ptr(payload, addr.addrlen), addr.raw, addr.addrlen);
|
||||
packetOkOverlay(interface, ob_current_ptr(payload), ob_remaining(payload), &addr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user