aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-28 15:59:39 -0400
committerDeterminant <[email protected]>2019-06-28 15:59:39 -0400
commit1e27eb1b25c2998ede63fc7a138477e1ae4b9508 (patch)
tree0caf3e3b92e7d1609262e584b9e7fa025feb9b5e
parentea27f0de65f79d7ee56e964f6c966e7c43c66f86 (diff)
...
-rw-r--r--network.go22
m---------salticidae0
-rw-r--r--test_p2p_stress/main.go14
3 files changed, 22 insertions, 14 deletions
diff --git a/network.go b/network.go
index 86c94dd..cdc882a 100644
--- a/network.go
+++ b/network.go
@@ -365,7 +365,7 @@ func (self MsgNetwork) AsPeerNetworkUnsafe() PeerNetwork {
// Create a MsgNetworkConn handle from a PeerNetworkConn (representing the same
// connection).
-func NewMsgNetworkConnFromPeerNetWorkConn(conn PeerNetworkConn) MsgNetworkConn {
+func NewMsgNetworkConnFromPeerNetworkConn(conn PeerNetworkConn) MsgNetworkConn {
res := MsgNetworkConnFromC(C.msgnetwork_conn_new_from_peernetwork_conn(conn.inner))
runtime.SetFinalizer(res, func(self MsgNetworkConn) { self.free() })
return res
@@ -373,7 +373,7 @@ func NewMsgNetworkConnFromPeerNetWorkConn(conn PeerNetworkConn) MsgNetworkConn {
// Create a PeerNetworkConn handle from a MsgNetworkConn (representing the same
// connection and forcing the conversion).
-func NewPeerNetworkConnFromMsgNetWorkConnUnsafe(conn MsgNetworkConn) PeerNetworkConn {
+func NewPeerNetworkConnFromMsgNetworkConnUnsafe(conn MsgNetworkConn) PeerNetworkConn {
res := PeerNetworkConnFromC(C.peernetwork_conn_new_from_msgnetwork_conn_unsafe(conn.inner))
runtime.SetFinalizer(res, func(self PeerNetworkConn) { self.free() })
return res
@@ -416,19 +416,27 @@ func (self PeerNetwork) MulticastMsgByMove(msg Msg, addrs []NetAddr) {
C.peernetwork_multicast_msg_by_move(self.inner, msg.inner, na.inner)
}
+// The C function pointer type which takes peernetwork_conn_t*, bool and void*
+// (passing in the custom user data allocated by C.malloc) as parameters.
+type PeerNetworkPeerCallback = C.peernetwork_peer_callback_t
+
+// Register a connection handler invoked when p2p connection is established/broken.
+func (self PeerNetwork) RegPeerHandler(callback PeerNetworkPeerCallback, userdata rawptr_t) {
+ C.peernetwork_reg_peer_handler(self.inner, callback, userdata)
+}
+
// The C function pointer type which takes netaddr_t* and void* (passing in the
// custom user data allocated by C.malloc) as parameters.
-type MsgNetworkUnknownPeerCallback = C.msgnetwork_unknown_peer_callback_t
+type PeerNetworkUnknownPeerCallback = C.peernetwork_unknown_peer_callback_t
// Register a connection handler invoked when a remote peer that is not in the
// list of known peers attempted to connect. By default configuration, the
// connection was rejected, and you can call AddPeer() to enroll this peer if
// you hope to establish the connection soon.
-func (self PeerNetwork) RegUnknownPeerHandler(callback MsgNetworkUnknownPeerCallback, userdata rawptr_t) {
+func (self PeerNetwork) RegUnknownPeerHandler(callback PeerNetworkUnknownPeerCallback, userdata rawptr_t) {
C.peernetwork_reg_unknown_peer_handler(self.inner, callback, userdata)
}
-
// The C pointer type for a ClientNetwork handle.
type CClientNetwork = *C.clientnetwork_t
type clientNetwork struct { inner CClientNetwork }
@@ -474,7 +482,7 @@ func (self MsgNetwork) AsClientNetworkUnsafe() ClientNetwork {
// Create a MsgNetworkConn handle from a ClientNetworkConn (representing the same
// connection).
-func NewMsgNetworkConnFromClientNetWorkConn(conn ClientNetworkConn) MsgNetworkConn {
+func NewMsgNetworkConnFromClientNetworkConn(conn ClientNetworkConn) MsgNetworkConn {
res := MsgNetworkConnFromC(C.msgnetwork_conn_new_from_clientnetwork_conn(conn.inner))
runtime.SetFinalizer(res, func(self MsgNetworkConn) { self.free() })
return res
@@ -482,7 +490,7 @@ func NewMsgNetworkConnFromClientNetWorkConn(conn ClientNetworkConn) MsgNetworkCo
// Create a ClientNetworkConn handle from a MsgNetworkConn (representing the same
// connection and forcing the conversion).
-func NewClientNetworkConnFromMsgNetWorkConnUnsafe(conn MsgNetworkConn) ClientNetworkConn {
+func NewClientNetworkConnFromMsgNetworkConnUnsafe(conn MsgNetworkConn) ClientNetworkConn {
res := ClientNetworkConnFromC(C.clientnetwork_conn_new_from_msgnetwork_conn_unsafe(conn.inner))
runtime.SetFinalizer(res, func(self ClientNetworkConn) { self.free() })
return res
diff --git a/salticidae b/salticidae
-Subproject 710e9e8961cf5039b425e66d2042942b7e4af0c
+Subproject 06b5a84602dc6a5dd76d82c9f88359cdb8cf52d
diff --git a/test_p2p_stress/main.go b/test_p2p_stress/main.go
index 06a1407..b358d5d 100644
--- a/test_p2p_stress/main.go
+++ b/test_p2p_stress/main.go
@@ -10,7 +10,7 @@ package main
// void onReceiveRand(msg_t *, msgnetwork_conn_t *, void *);
// void onReceiveAck(msg_t *, msgnetwork_conn_t *, void *);
// void onStopLoop(threadcall_handle_t *, void *);
-// void connHandler(msgnetwork_conn_t *, bool, void *);
+// void peerHandler(peernetwork_conn_t *, bool, void *);
// void errorHandler(SalticidaeCError *, bool, void *);
// void onTimeout(timerev_t *, void *);
// typedef struct timeout_callback_context_t {
@@ -214,12 +214,12 @@ func onReceiveAck(_msg *C.struct_msg_t, _conn *C.struct_msgnetwork_conn_t, userd
}
}
-//export connHandler
-func connHandler(_conn *C.struct_msgnetwork_conn_t, connected C.bool, userdata unsafe.Pointer) {
- conn := salticidae.MsgNetworkConnFromC(salticidae.CMsgNetworkConn(_conn))
- id := *(*int)(userdata)
- app := &apps[id]
+//export peerHandler
+func peerHandler(_conn *C.struct_peernetwork_conn_t, connected C.bool, userdata unsafe.Pointer) {
if connected {
+ conn := salticidae.NewMsgNetworkConnFromPeerNetworkConn(salticidae.PeerNetworkConnFromC(salticidae.CPeerNetworkConn(_conn)))
+ id := *(*int)(userdata)
+ app := &apps[id]
if conn.GetMode() == salticidae.CONN_MODE_ACTIVE {
tc := app.getTC(addr2id(conn.GetAddr()))
tc.state = 1
@@ -288,7 +288,7 @@ func main() {
mnet := net.AsMsgNetwork()
mnet.RegHandler(MSG_OPCODE_RAND, salticidae.MsgNetworkMsgCallback(C.onReceiveRand), _i)
mnet.RegHandler(MSG_OPCODE_ACK, salticidae.MsgNetworkMsgCallback(C.onReceiveAck), _i)
- mnet.RegConnHandler(salticidae.MsgNetworkConnCallback(C.connHandler), _i)
+ net.RegPeerHandler(salticidae.PeerNetworkPeerCallback(C.peerHandler), _i)
mnet.RegErrorHandler(salticidae.MsgNetworkErrorCallback(C.errorHandler), _i)
mnet.Start()
}