aboutsummaryrefslogtreecommitdiff
path: root/network.go
blob: a4cac022f87751991aa08da5ce227a66328bfbef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package salticidae

// #include "salticidae/network.h"
import "C"

type MsgNetwork = *C.struct_msgnetwork_t

type MsgNetworkConn = *C.struct_msgnetwork_conn_t

type MsgNetworkConnMode = C.msgnetwork_conn_mode_t


func (self MsgNetworkConn) GetNet() MsgNetwork {
    return C.msgnetwork_conn_get_net(self)
}

var (
    CONN_MODE_ACTIVE = MsgNetworkConnMode(C.CONN_MODE_ACTIVE)
    CONN_MODE_PASSIVE = MsgNetworkConnMode(C.CONN_MODE_PASSIVE)
    CONN_MODE_DEAD = MsgNetworkConnMode(C.CONN_MODE_DEAD)
)

func (self MsgNetworkConn) GetMode() MsgNetworkConnMode {
    return C.msgnetwork_conn_get_mode(self)
}

func (self MsgNetworkConn) GetAddr() NetAddr {
    return C.msgnetwork_conn_get_addr(self)
}

type MsgNetworkConfig = *C.struct_msgnetwork_config_t

func NewMsgNetworkConfig() MsgNetworkConfig { return C.msgnetwork_config_new() }

func (self MsgNetworkConfig) Free() { C.msgnetwork_config_free(self) }

func NewMsgNetwork(ec EventContext, config MsgNetworkConfig) MsgNetwork {
    return C.msgnetwork_new(ec, config)
}

func (self MsgNetwork) Free() { C.msgnetwork_free(self) }
func (self MsgNetwork) Listen(addr NetAddr) { C.msgnetwork_listen(self, addr) }
func (self MsgNetwork) Start() { C.msgnetwork_start(self) }

func (self MsgNetwork) SendMsg(msg Msg, conn MsgNetworkConn) { C.msgnetwork_send_msg(self, msg, conn) }
func (self MsgNetwork) Connect(addr NetAddr) { C.msgnetwork_connect(self, addr) }
func (self MsgNetwork) Terminate(conn MsgNetworkConn) { C.msgnetwork_terminate(self, conn) }

type MsgNetworkMsgCallback = C.msgnetwork_msg_callback_t
type MsgNetworkConnCallback = C.msgnetwork_conn_callback_t

func (self MsgNetwork) RegHandler(opcode Opcode, callback MsgNetworkMsgCallback, userdata rawptr_t) {
    C.msgnetwork_reg_handler(self, C._opcode_t(opcode), callback, userdata)
}

func (self MsgNetwork) RegConnHandler(callback MsgNetworkConnCallback, userdata rawptr_t) {
    C.msgnetwork_reg_conn_handler(self, callback, userdata)
}

type PeerNetwork = *C.struct_peernetwork_t

type PeerNetworkConn = *C.struct_peernetwork_conn_t

type PeerNetworkConfig = *C.struct_peernetwork_config_t

func NewPeerNetworkConfig() PeerNetworkConfig { return C.peernetwork_config_new() }

func NewPeerNetwork(ec EventContext, config PeerNetworkConfig) PeerNetwork {
    return C.peernetwork_new(ec, config)
}

func (self PeerNetwork) Free() { C.peernetwork_free(self) }

func (self PeerNetwork) AddPeer(paddr NetAddr) { C.peernetwork_add_peer(self, paddr) }

func (self PeerNetwork) HasPeer(paddr NetAddr) bool { return bool(C.peernetwork_has_peer(self, paddr)) }

func (self PeerNetwork) GetPeerConn(paddr NetAddr) PeerNetworkConn { return C.peernetwork_get_peer_conn(self, paddr) }

func (self PeerNetwork) AsMsgNetwork() MsgNetwork { return C.peernetwork_as_msgnetwork(self) }

func NewMsgNetworkConnFromPeerNetWorkConn(conn PeerNetworkConn) MsgNetworkConn { return C.msgnetwork_conn_new_from_peernetwork_conn(conn) }

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) {
    base := uintptr(rawptr_t(&paddrs[0]))
    C.peernetwork_multicast_msg(self, _moved_msg, (*C.struct_netaddr_t)(rawptr_t(base)), C.size_t(len(paddrs)))
}

func (self PeerNetwork) Listen(listenAddr NetAddr) { C.peernetwork_listen(self, listenAddr) }