aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2019-06-06 17:00:25 -0400
committerDeterminant <[email protected]>2019-06-06 17:00:25 -0400
commitf32e3109526f2d4e980c03dd65f7c94edff4d2b2 (patch)
tree990cd76066550bb6402e5c85d462ce86a570beb0
init
-rw-r--r--.gitmodules3
-rw-r--r--demo/main.go23
m---------salticidae0
-rw-r--r--salticidae.go40
4 files changed, 66 insertions, 0 deletions
diff --git a/.gitmodules b/.gitmodules
new file mode 100644
index 0000000..e311f67
--- /dev/null
+++ b/.gitmodules
@@ -0,0 +1,3 @@
+[submodule "salticidae"]
+ path = salticidae
+ url = https://github.com/Determinant/salticidae.git
diff --git a/demo/main.go b/demo/main.go
new file mode 100644
index 0000000..e156f45
--- /dev/null
+++ b/demo/main.go
@@ -0,0 +1,23 @@
+package main
+
+import "salticidae-go"
+
+func run(my_addr string, other_addr string) {
+ netconfig := salticidae.NewMsgNetworkConfig()
+ ec := salticidae.NewEventContext()
+ net := salticidae.NewMsgNetwork(ec, netconfig)
+ listen_addr := salticidae.NewAddrFromIPPortString(my_addr)
+ connect_addr := salticidae.NewAddrFromIPPortString(other_addr)
+
+ net.Start()
+ net.Listen(listen_addr)
+ net.Connect(connect_addr)
+ ec.Dispatch()
+}
+
+func main() {
+ alice := "127.0.0.1:10000"
+ bob := "127.0.0.1:10001"
+ go run(alice, bob)
+ run(bob, alice)
+}
diff --git a/salticidae b/salticidae
new file mode 160000
+Subproject f7050c145e81a70be85bb0287044abdfa7ba444
diff --git a/salticidae.go b/salticidae.go
new file mode 100644
index 0000000..4a8712a
--- /dev/null
+++ b/salticidae.go
@@ -0,0 +1,40 @@
+package salticidae
+
+
+// #cgo CFLAGS: -I${SRCDIR}/salticidae/include/
+// #cgo LDFLAGS: ${SRCDIR}/salticidae/libsalticidae.so -Wl,-rpath=${SRCDIR}/salticidae/
+// #include <stdlib.h>
+// #include "salticidae/netaddr.h"
+// #include "salticidae/network.h"
+import "C"
+import "unsafe"
+
+type rawptr_t = unsafe.Pointer
+
+type NetAddr = *C.struct_netaddr_t
+
+func NewAddrFromIPPortString(addr string) (res NetAddr) {
+ c_str := C.CString(addr)
+ res = C.netaddr_new_from_sipport(c_str)
+ C.free(rawptr_t(c_str))
+ return
+}
+
+type MsgNetwork = *C.struct_msgnetwork_t
+
+type EventContext = *C.struct_eventcontext_t
+
+func NewEventContext() EventContext { return C.eventcontext_new() }
+func (self EventContext) Dispatch() { C.eventcontext_dispatch(self) }
+
+type MsgNetworkConfig = *C.struct_msgnetwork_config_t
+
+func NewMsgNetworkConfig() MsgNetworkConfig { return C.msgnetwork_config_new() }
+
+func NewMsgNetwork(ec EventContext, config MsgNetworkConfig) MsgNetwork {
+ return C.msgnetwork_new(ec, config)
+}
+
+func (self MsgNetwork) Start() { C.msgnetwork_start(self) }
+func (self MsgNetwork) Listen(addr NetAddr) { C.msgnetwork_listen(self, addr) }
+func (self MsgNetwork) Connect(addr NetAddr) { C.msgnetwork_connect(self, addr) }