mirror of
https://github.com/ZeroTier/ZeroTierOne
synced 2025-08-14 10:37:33 -07:00
A bunch of CLI work
This commit is contained in:
parent
c4504fd3ff
commit
7fc78129f4
19 changed files with 225 additions and 153 deletions
|
@ -45,7 +45,7 @@ type Identity struct {
|
|||
// NewIdentityFromString generates a new identity from its string representation.
|
||||
// The private key is imported as well if it is present.
|
||||
func NewIdentityFromString(s string) (*Identity, error) {
|
||||
ss := strings.Split(s, ":")
|
||||
ss := strings.Split(strings.TrimSpace(s), ":")
|
||||
if len(ss) < 3 {
|
||||
return nil, ErrInvalidParameter
|
||||
}
|
||||
|
|
|
@ -43,7 +43,7 @@ func (i *InetAddress) Less(i2 *InetAddress) bool {
|
|||
// NewInetAddressFromString parses an IP[/port] format address
|
||||
func NewInetAddressFromString(s string) *InetAddress {
|
||||
i := new(InetAddress)
|
||||
ss := strings.Split(s, "/")
|
||||
ss := strings.Split(strings.TrimSpace(s), "/")
|
||||
if len(ss) > 0 {
|
||||
i.IP = net.ParseIP(ss[0])
|
||||
i4 := i.IP.To4()
|
||||
|
|
|
@ -151,6 +151,25 @@ func NewLocatorFromBytes(b []byte) (*Locator, error) {
|
|||
return &loc, nil
|
||||
}
|
||||
|
||||
// MakeTXTRecords creates secure DNS TXT records for this locator
|
||||
func (l *Locator) MakeTXTRecords(key *LocatorDNSSigningKey) ([]string, error) {
|
||||
if key == nil || len(l.Bytes) == 0 || len(key.PrivateKey) == 0 {
|
||||
return nil, ErrInvalidParameter
|
||||
}
|
||||
var results [256][256]C.char
|
||||
cName := C.CString(key.SecureDNSName)
|
||||
defer C.free(unsafe.Pointer(cName))
|
||||
count := int(C.ZT_GoLocator_makeSignedTxtRecords((*C.uint8_t)(&l.Bytes[0]), C.uint(len(l.Bytes)), cName, (*C.uint8_t)(&key.PrivateKey[0]), C.uint(len(key.PrivateKey)), &results[0]))
|
||||
if count > 0 {
|
||||
var t []string
|
||||
for i := 0; i < int(count); i++ {
|
||||
t = append(t, C.GoString(&results[i][0]))
|
||||
}
|
||||
return t, nil
|
||||
}
|
||||
return nil, ErrInternal
|
||||
}
|
||||
|
||||
// MarshalJSON marshals this Locator as its byte encoding
|
||||
func (l *Locator) MarshalJSON() ([]byte, error) {
|
||||
return json.Marshal(l)
|
||||
|
|
|
@ -71,6 +71,9 @@ const (
|
|||
// AFInet6 is the address family for IPv6
|
||||
AFInet6 = C.AF_INET6
|
||||
|
||||
networkConfigOpUp int = C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP
|
||||
networkConfigOpUpdate int = C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_CONFIG_UPDATE
|
||||
|
||||
defaultVirtualNetworkMTU = C.ZT_DEFAULT_MTU
|
||||
)
|
||||
|
||||
|
@ -548,21 +551,11 @@ func (n *Node) Roots() []*Root {
|
|||
if rl != nil {
|
||||
for i := 0; i < int(rl.count); i++ {
|
||||
root := (*C.ZT_Root)(unsafe.Pointer(uintptr(unsafe.Pointer(rl)) + C.sizeof_ZT_RootList))
|
||||
id, err := NewIdentityFromString(C.GoString(root.identity))
|
||||
if err == nil {
|
||||
var addrs []InetAddress
|
||||
for j := uintptr(0); j < uintptr(root.addressCount); j++ {
|
||||
a := NewInetAddressFromSockaddr(unsafe.Pointer(uintptr(unsafe.Pointer(root.addresses)) + (j * C.sizeof_struct_sockaddr_storage)))
|
||||
if a != nil && a.Valid() {
|
||||
addrs = append(addrs, *a)
|
||||
}
|
||||
}
|
||||
loc, _ := NewLocatorFromBytes(C.GoBytes(root.locator, C.int(root.locatorSize)))
|
||||
if loc != nil {
|
||||
roots = append(roots, &Root{
|
||||
Name: C.GoString(root.name),
|
||||
Identity: id,
|
||||
Addresses: addrs,
|
||||
Preferred: root.preferred != 0,
|
||||
Online: root.online != 0,
|
||||
Name: C.GoString(root.name),
|
||||
Locator: loc,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
@ -584,11 +577,11 @@ func (n *Node) SetRoot(name string, locator *Locator) error {
|
|||
}
|
||||
var lb []byte
|
||||
if locator != nil {
|
||||
lb = locator.Bytes()
|
||||
lb = locator.Bytes
|
||||
}
|
||||
var lbp unsafe.Pointer
|
||||
if len(lb) > 0 {
|
||||
lbp = &lb[0]
|
||||
lbp = unsafe.Pointer(&lb[0])
|
||||
}
|
||||
cn := C.CString(name)
|
||||
defer C.free(unsafe.Pointer(cn))
|
||||
|
@ -925,8 +918,8 @@ func goVirtualNetworkConfigFunc(gn, _ unsafe.Pointer, nwid C.uint64_t, op C.int,
|
|||
node.networksLock.RUnlock()
|
||||
|
||||
if network != nil {
|
||||
switch op {
|
||||
case C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP, C.ZT_VIRTUAL_NETWORK_CONFIG_OPERATION_UP:
|
||||
switch int(op) {
|
||||
case networkConfigOpUp, networkConfigOpUpdate:
|
||||
ncc := (*C.ZT_VirtualNetworkConfig)(conf)
|
||||
if network.networkConfigRevision() > uint64(ncc.netconfRevision) {
|
||||
return
|
||||
|
|
|
@ -15,8 +15,6 @@ package zerotier
|
|||
|
||||
// Root describes a root server used to find and establish communication with other nodes.
|
||||
type Root struct {
|
||||
Name string
|
||||
Locator *Locator
|
||||
Preferred bool
|
||||
Online bool
|
||||
Name string
|
||||
Locator *Locator
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue