aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-11 14:27:26 -0400
committerDeterminant <[email protected]>2019-06-11 14:27:26 -0400
commit69d0435bcc88cc8b4c140b876df5fcfb827b40ef (patch)
treeabeafbf520d345398ac5081675df17891c862413
parent1b2215ae2c792f96765a15c7ffcc6f20e3046cc7 (diff)
...
-rw-r--r--netaddr.go13
-rw-r--r--network.go8
m---------salticidae0
-rw-r--r--stream.go6
-rw-r--r--test_p2p_stress/main.go4
5 files changed, 19 insertions, 12 deletions
diff --git a/netaddr.go b/netaddr.go
index 3836a9c..a631689 100644
--- a/netaddr.go
+++ b/netaddr.go
@@ -4,7 +4,8 @@ package salticidae
// #include "salticidae/netaddr.h"
import "C"
-type NetAddr = *C.struct_netaddr_t
+type NetAddr = *C.netaddr_t
+type NetAddrArray = *C.netaddr_array_t
func NewAddrFromIPPortString(addr string) (res NetAddr) {
c_str := C.CString(addr)
@@ -22,3 +23,13 @@ func (self NetAddr) IsNull() bool { return bool(C.netaddr_is_null(self)) }
func (self NetAddr) GetIP() uint32 { return uint32(C.netaddr_get_ip(self)) }
func (self NetAddr) GetPort() uint16 { return uint16(C.netaddr_get_port(self)) }
+
+func NewAddrArrayFromAddrs(arr []NetAddr) NetAddrArray {
+ size := len(arr)
+ if size > 0 {
+ base := (**C.netaddr_t)(&arr[0])
+ return C.netaddr_array_new_from_addrs(base, C.size_t(size))
+ } else {
+ return C.netaddr_array_new()
+ }
+}
diff --git a/network.go b/network.go
index 78d798a..262e460 100644
--- a/network.go
+++ b/network.go
@@ -84,12 +84,8 @@ func NewMsgNetworkConnFromPeerNetWorkConn(conn PeerNetworkConn) MsgNetworkConn {
func (self PeerNetwork) SendMsg(_moved_msg Msg, paddr NetAddr) { C.peernetwork_send_msg(self, _moved_msg, paddr) }
func (self PeerNetwork) MulticastMsg(_moved_msg Msg, paddrs []NetAddr) {
- size := len(paddrs)
- if size > 0 {
- base := (C.netaddr_t *)(&paddrs[0])
- C.peernetwork_multicast_msg(
- self, _moved_msg, base, C.size_t(size))
- }
+ na := NewAddrArrayFromAddrs(paddrs)
+ C.peernetwork_multicast_msg(self, _moved_msg, na)
}
func (self PeerNetwork) Listen(listenAddr NetAddr) { C.peernetwork_listen(self, listenAddr) }
diff --git a/salticidae b/salticidae
-Subproject 05ffb2ce9f4a0cbaca05a1d46b040743d661ce2
+Subproject ef377f5d85503451a16d50fbc535a7537a28b57
diff --git a/stream.go b/stream.go
index ebfaaf4..6a5d549 100644
--- a/stream.go
+++ b/stream.go
@@ -20,7 +20,7 @@ func NewDataStreamFromBytes(bytes []byte) DataStream {
size := len(bytes)
if size > 0 {
base := (*C.uint8_t)(&bytes[0])
- return C.datastream_new_from_bytes(base, base + uintptr(size))
+ return C.datastream_new_from_bytes(base, C.size_t(size))
} else {
return C.datastream_new()
}
@@ -56,7 +56,7 @@ func (self DataStream) PutData(bytes []byte) {
size := len(bytes)
if size > 0 {
base := (*C.uint8_t)(&bytes[0])
- C.datastream_put_data(self, base, base + uintptr(size))
+ C.datastream_put_data(self, base, C.size_t(size))
}
}
@@ -73,7 +73,7 @@ func (self DataStream) GetI64() int64 { return int64(C.datastream_get_i64(self))
func (self DataStream) GetDataInPlace(length int) []byte {
base := C.datastream_get_data_inplace(self, C.size_t(length))
- return C.GoBytes(base, C.int(length))
+ return C.GoBytes(rawptr_t(base), C.int(length))
}
type UInt256 = *C.uint256_t
diff --git a/test_p2p_stress/main.go b/test_p2p_stress/main.go
index 4534c4f..d80699d 100644
--- a/test_p2p_stress/main.go
+++ b/test_p2p_stress/main.go
@@ -15,8 +15,8 @@ package main
// uint64_t addr_id;
// msgnetwork_conn_t *conn;
// } timeout_callback_context_t;
-// timeout_callback_context_t *timeout_callback_context_new() {
-// timeout_callback_context_t *ctx = malloc(sizeof(timeout_callback_context_t);
+// static timeout_callback_context_t *timeout_callback_context_new() {
+// timeout_callback_context_t *ctx = malloc(sizeof(timeout_callback_context_t));
// ctx->conn = NULL;
// return ctx;
// }