This commit is contained in:
Adam Ierymenko 2019-09-20 21:00:54 -07:00
parent b540181990
commit fbf74d3baa
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
5 changed files with 52 additions and 11 deletions

View file

@ -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 {

View file

@ -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
}

View file

@ -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 <stdint.h>

View file

@ -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 <stdint.h>
//#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
}

View file

@ -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