diff --git a/go/pkg/zerotier/nativetap.go b/go/pkg/zerotier/nativetap.go index 1c448236b..83e8050d9 100644 --- a/go/pkg/zerotier/nativetap.go +++ b/go/pkg/zerotier/nativetap.go @@ -38,6 +38,18 @@ type nativeTap struct { multicastGroupHandlersLock sync.Mutex } +var _ Tap = &nativeTap{} + +// Type returns a human-readable description of this tap implementation +func (t *nativeTap) Type() string { + return "native" +} + +// Error gets this tap device's error status +func (t *nativeTap) Error() (int, string) { + return 0, "" +} + // SetEnabled sets this tap's enabled state func (t *nativeTap) SetEnabled(enabled bool) { if enabled && atomic.SwapUint32(&t.enabled, 1) == 0 { diff --git a/go/pkg/zerotier/network.go b/go/pkg/zerotier/network.go index e2a4b5b14..c2c3cd566 100644 --- a/go/pkg/zerotier/network.go +++ b/go/pkg/zerotier/network.go @@ -94,23 +94,29 @@ type NetworkConfig struct { // MulticastSubscriptions are this device's current multicast subscriptions MulticastSubscriptions []MulticastGroup - // PortDeviceType is a human-readable description of this port's implementation type or name - PortDeviceType string + // Enabled is true if this network's tap device is enabled + Enabled bool - // PortDeviceName is the OS-specific device name (e.g. tun0 or feth1856) for this network's virtual port - PortDeviceName string + // TapDeviceType is a human-readable description of this network's tap device type + TapDeviceType string - // PortErrorCode is an OS-specific error code returned by the virtual NIC driver - PortErrorCode int + // TapDevicePort is the OS-specific virtual device name (if applicable) + TapDevicePort string + + // TapErrorCode is an implementation-specific error code from the tap device (0 for no error) + TapErrorCode int + + // TapError is a human-readable description of this tap device's error state or an empty string if there is no error + TapError string } // Network is a currently joined network type Network struct { id NetworkID config NetworkConfig - configLock sync.RWMutex tap Tap - tapLock sync.Mutex + configLock sync.RWMutex + tapLock sync.RWMutex } // ID gets this network's unique ID @@ -119,13 +125,17 @@ func (n *Network) ID() NetworkID { return n.id } // Config returns a copy of this network's current configuration func (n *Network) Config() NetworkConfig { n.configLock.RLock() + n.tapLock.RLock() + defer n.tapLock.RUnlock() defer n.configLock.RUnlock() + n.config.Enabled = n.tap.Enabled() + n.config.TapErrorCode, n.config.TapError = n.tap.Error() return n.config } // Tap gets this network's tap device func (n *Network) Tap() Tap { - n.tapLock.Lock() - defer n.tapLock.Unlock() + n.tapLock.RLock() + defer n.tapLock.RUnlock() return n.tap } diff --git a/go/pkg/zerotier/node-callbacks.go b/go/pkg/zerotier/node-callbacks.go index 98efb9ddc..fd9593df1 100644 --- a/go/pkg/zerotier/node-callbacks.go +++ b/go/pkg/zerotier/node-callbacks.go @@ -13,6 +13,8 @@ package zerotier +// These are exported callbacks that are called from the C++ code in GoGlue.cpp + //#cgo CFLAGS: -O3 //#define ZT_CGO 1 //#include diff --git a/go/pkg/zerotier/node.go b/go/pkg/zerotier/node.go index 4ad2bb65c..d31c77728 100644 --- a/go/pkg/zerotier/node.go +++ b/go/pkg/zerotier/node.go @@ -22,7 +22,7 @@ import ( ) //#cgo CFLAGS: -O3 -//#cgo LDFLAGS: ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/go/native/libzt_go_native.a -lc++ +//#cgo LDFLAGS: ${SRCDIR}/../../../build/node/libzt_core.a ${SRCDIR}/../../../build/go/native/libzt_go_native.a -lc++ -lpthread //#define ZT_CGO 1 //#include //#include "../../native/GoGlue.h" @@ -50,6 +50,8 @@ const ( CoreVersionBuild int = C.ZEROTIER_ONE_VERSION_BUILD ) +////////////////////////////////////////////////////////////////////////////// + // Node is an instance of a ZeroTier node type Node struct { gn *C.ZT_GoNode @@ -92,6 +94,19 @@ func (n *Node) Close() { } } +// Join joins a network +// If tap is nil, the default system tap for this OS/platform is used (if available). +func (n *Node) Join(nwid uint64, tap Tap) (*Network, error) { + return nil, nil +} + +// Leave leaves a network +func (n *Node) Leave(nwid uint64) error { + return nil +} + +////////////////////////////////////////////////////////////////////////////// + func (n *Node) pathCheck(ztAddress uint64, af int, ip net.IP, port int) bool { return true } diff --git a/go/pkg/zerotier/tap.go b/go/pkg/zerotier/tap.go index d6833bedc..310ec2a11 100644 --- a/go/pkg/zerotier/tap.go +++ b/go/pkg/zerotier/tap.go @@ -17,6 +17,8 @@ import "net" // Tap represents an Ethernet tap connecting a virtual network to a device or something else "real" type Tap interface { + Type() string + Error() (int, string) SetEnabled(enabled bool) Enabled() bool AddIP(ip net.IPNet) error