aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-17 02:13:46 -0400
committerDeterminant <[email protected]>2019-06-17 02:13:46 -0400
commitc69b0150fe0c50b91c7c8a406f096de8e9cf62fc (patch)
treea8643b0db8133cf022b1b2854329fec633dd805d
parent4dc7feb8b15e0a76cc95e5a80fce363cca637856 (diff)
add unknown peer callback to C API
-rw-r--r--include/salticidae/network.h8
-rw-r--r--src/network.cpp8
2 files changed, 14 insertions, 2 deletions
diff --git a/include/salticidae/network.h b/include/salticidae/network.h
index 6fef98a..466272f 100644
--- a/include/salticidae/network.h
+++ b/include/salticidae/network.h
@@ -952,7 +952,8 @@ extern "C" {
void salticidae_injected_msg_callback(const msg_t *msg, msgnetwork_conn_t *conn);
-// MsgNetwork
+/* MsgNetwork */
+
msgnetwork_config_t *msgnetwork_config_new();
void msgnetwork_config_free(const msgnetwork_config_t *self);
void msgnetwork_config_burst_size(msgnetwork_config_t *self, size_t burst_size);
@@ -987,7 +988,7 @@ msgnetwork_t *msgnetwork_conn_get_net(const msgnetwork_conn_t *conn);
msgnetwork_conn_mode_t msgnetwork_conn_get_mode(const msgnetwork_conn_t *conn);
const netaddr_t *msgnetwork_conn_get_addr(const msgnetwork_conn_t *conn);
-// PeerNetwork
+/* PeerNetwork */
peernetwork_config_t *peernetwork_config_new();
void peernetwork_config_free(const peernetwork_config_t *self);
@@ -1013,6 +1014,9 @@ void peernetwork_multicast_msg_by_move(peernetwork_t *self, msg_t *_moved_msg, c
void peernetwork_listen(peernetwork_t *self, const netaddr_t *listen_addr, SalticidaeCError *err);
void peernetwork_stop(peernetwork_t *self);
+typedef void (*msgnetwork_unknown_peer_callback_t)(const netaddr_t *, void *userdata);
+void peernetwork_reg_unknown_peer_handler(peernetwork_t *self, msgnetwork_unknown_peer_callback_t cb, void *userdata);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/network.cpp b/src/network.cpp
index 0a83e39..8094ff2 100644
--- a/src/network.cpp
+++ b/src/network.cpp
@@ -233,6 +233,14 @@ void peernetwork_listen(peernetwork_t *self, const netaddr_t *listen_addr, Salti
void peernetwork_stop(peernetwork_t *self) { self->stop(); }
+void peernetwork_reg_unknown_peer_handler(peernetwork_t *self,
+ msgnetwork_unknown_peer_callback_t cb,
+ void *userdata) {
+ self->reg_unknown_peer_handler([=](const NetAddr &addr) {
+ cb(&addr, userdata);
+ });
+}
+
}
#endif