Root admin stuff

This commit is contained in:
Adam Ierymenko 2019-09-30 09:32:00 -07:00
parent 4303c43db7
commit b0d222768a
No known key found for this signature in database
GPG key ID: C8877CF2D7A5D7F3
16 changed files with 217 additions and 46 deletions

View file

@ -558,7 +558,7 @@ func (n *Node) Roots() []*Root {
}
}
roots = append(roots, &Root{
DNSName: C.GoString(root.dnsName),
Name: C.GoString(root.dnsName),
Identity: id,
Addresses: addrs,
Preferred: (root.preferred != 0),
@ -571,6 +571,42 @@ func (n *Node) Roots() []*Root {
return roots
}
// SetRoot sets or updates a root.
// Name can be a DNS name (preferably secure) for DNS fetched locators or can be
// the empty string for static roots. If the name is empty then the locator must
// be non-nil.
func (n *Node) SetRoot(name string, locator *Locator) error {
if len(name) == 0 {
if locator == nil {
return ErrInvalidParameter
}
name = locator.Identity.address.String()
}
var lb []byte
if locator != nil {
lb = locator.Bytes()
}
var lbp unsafe.Pointer
if len(lb) > 0 {
lbp = unsafe.Pointer(&lb[0])
}
cn := C.CString(name)
defer C.free(unsafe.Pointer(cn))
if C.ZT_Node_setRoot(n.zn, cn, lbp, C.uint(len(lb))) != 0 {
return ErrInternal
}
return nil
}
// RemoveRoot removes a root.
// For static roots the name should be the ZeroTier address.
func (n *Node) RemoveRoot(name string) {
cn := C.CString(name)
defer C.free(unsafe.Pointer(cn))
C.ZT_Node_removeRoot(n.zn, cn)
return
}
// Peers retrieves a list of current peers
func (n *Node) Peers() []*Peer {
var peers []*Peer