mirror of
https://github.com/servalproject/serval-dna.git
synced 2025-02-20 09:26:37 +00:00
Fix mdp support and Java API for binding to all keys in the keyring
This commit is contained in:
parent
ff6b15748d
commit
7474e8afea
@ -13,11 +13,14 @@ public abstract class AbstractMdpProtocol<T> extends ChannelSelector.Handler {
|
||||
protected final AsyncResult<T> results;
|
||||
|
||||
public AbstractMdpProtocol(ChannelSelector selector, int loopbackMdpPort, AsyncResult<T> results) throws IOException {
|
||||
this(selector, loopbackMdpPort, results, 0);
|
||||
this(selector, loopbackMdpPort, results, SubscriberId.ANY, 0);
|
||||
}
|
||||
public AbstractMdpProtocol(ChannelSelector selector, int loopbackMdpPort, AsyncResult<T> results, int port) throws IOException {
|
||||
this(selector, loopbackMdpPort, results, SubscriberId.ANY, port);
|
||||
}
|
||||
public AbstractMdpProtocol(ChannelSelector selector, int loopbackMdpPort, AsyncResult<T> results, SubscriberId sid, int port) throws IOException {
|
||||
this.socket = new MdpSocket(loopbackMdpPort);
|
||||
socket.bind(port);
|
||||
socket.bind(sid, port);
|
||||
this.selector = selector;
|
||||
this.results = results;
|
||||
selector.register(this);
|
||||
|
@ -67,11 +67,15 @@ public class MdpSocket{
|
||||
channel.socket().setSoTimeout(5000);
|
||||
// should throw MdpError on bind failures
|
||||
receive(packet);
|
||||
try {
|
||||
this.sid = packet.getLocalSid();
|
||||
} catch (AbstractId.InvalidBinaryException e) {
|
||||
e.printStackTrace();
|
||||
throw new MdpError(e);
|
||||
if (sid.isBroadcast()){
|
||||
this.sid = sid;
|
||||
}else{
|
||||
try {
|
||||
this.sid = packet.getLocalSid();
|
||||
} catch (AbstractId.InvalidBinaryException e) {
|
||||
e.printStackTrace();
|
||||
throw new MdpError(e);
|
||||
}
|
||||
}
|
||||
this.port = packet.getLocalPort();
|
||||
}
|
||||
@ -87,7 +91,8 @@ public class MdpSocket{
|
||||
public void send(MdpPacket packet) throws IOException {
|
||||
if (sid==null)
|
||||
bind(SubscriberId.ANY, 0);
|
||||
packet.setLocalSid(this.sid);
|
||||
if (!this.sid.isBroadcast())
|
||||
packet.setLocalSid(this.sid);
|
||||
packet.setLocalPort(this.port);
|
||||
packet.send(channel);
|
||||
}
|
||||
|
@ -227,7 +227,7 @@ public class ServalDCommand
|
||||
public static int keyringList(final AsyncResult<IdentityResult> results) throws ServalDFailureException
|
||||
{
|
||||
// FIXME, this is a little hacky as the number of tags is unknown so we don't have a fixed number of columns
|
||||
return keyringList(new AbstractJniResults() {
|
||||
return command(new AbstractJniResults() {
|
||||
IdentityResult id = null;
|
||||
long fields=0;
|
||||
String columnName;
|
||||
@ -253,12 +253,12 @@ public class ServalDCommand
|
||||
public void putString(String value) {
|
||||
id.setColumnName(0, columnName);
|
||||
id.putString(value);
|
||||
if (fields--==0){
|
||||
if (--fields==0){
|
||||
results.result(id);
|
||||
id=null;
|
||||
}
|
||||
}
|
||||
});
|
||||
}, "keyring", "list", "--full");
|
||||
}
|
||||
|
||||
public static int keyringList(IJniResults results) throws ServalDFailureException{
|
||||
|
@ -1414,11 +1414,12 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
|
||||
if ((!free_slot) && mdp_bindings[i].port==0)
|
||||
free_slot=&mdp_bindings[i];
|
||||
|
||||
if (mdp_bindings[i].port == header->local.port
|
||||
&& mdp_bindings[i].subscriber == internal_header.source){
|
||||
|
||||
binding = &mdp_bindings[i];
|
||||
break;
|
||||
if (mdp_bindings[i].port == header->local.port){
|
||||
if (mdp_bindings[i].subscriber == internal_header.source){
|
||||
binding = &mdp_bindings[i];
|
||||
break;
|
||||
}else if(!mdp_bindings[i].subscriber)
|
||||
binding = &mdp_bindings[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1463,8 +1464,8 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
|
||||
if (!binding
|
||||
|| binding->internal
|
||||
|| cmp_sockaddr(&binding->client, client)!=0){
|
||||
WHYF("Already bound by someone else? %s vs %s",
|
||||
alloca_socket_address(&binding->client),
|
||||
WHYF("That port is not bound by you %s vs %s",
|
||||
binding?alloca_socket_address(&binding->client):"(none)",
|
||||
alloca_socket_address(client));
|
||||
mdp_reply_error(client, header);
|
||||
}
|
||||
@ -1499,7 +1500,9 @@ static void mdp_process_packet(struct socket_address *client, struct mdp_header
|
||||
|| !internal_header.source
|
||||
|| header->local.port == 0
|
||||
|| cmp_sockaddr(&binding->client, client)!=0){
|
||||
WHY("Can't send data packet, no matching port binding!");
|
||||
WHYF("Can't send data packet, no matching port binding for %s:%d!",
|
||||
alloca_tohex_sid_t(header->local.sid),
|
||||
header->local.port);
|
||||
mdp_reply_error(client, header);
|
||||
return;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user