mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-04-28 14:15:06 +03:00
Link refactoring, admin socket changes
This commit is contained in:
parent
c7ee7d9681
commit
7afa23be4c
32 changed files with 1206 additions and 1130 deletions
|
@ -2,12 +2,25 @@ package core
|
|||
|
||||
import (
|
||||
"crypto/ed25519"
|
||||
"crypto/x509"
|
||||
"fmt"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func (c *Core) _applyOption(opt SetupOption) {
|
||||
func (c *Core) _applyOption(opt SetupOption) (err error) {
|
||||
switch v := opt.(type) {
|
||||
case RootCertificate:
|
||||
cert := x509.Certificate(v)
|
||||
if c.config.roots == nil {
|
||||
c.config.roots = x509.NewCertPool()
|
||||
}
|
||||
c.config.roots.AddCert(&cert)
|
||||
case Peer:
|
||||
c.config._peers[v] = nil
|
||||
u, err := url.Parse(v.URI)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to parse peering URI: %w", err)
|
||||
}
|
||||
return c.links.add(u, v.SourceInterface, linkTypePersistent)
|
||||
case ListenAddress:
|
||||
c.config._listeners[v] = struct{}{}
|
||||
case NodeInfo:
|
||||
|
@ -19,12 +32,14 @@ func (c *Core) _applyOption(opt SetupOption) {
|
|||
copy(pk[:], v)
|
||||
c.config._allowedPublicKeys[pk] = struct{}{}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
type SetupOption interface {
|
||||
isSetupOption()
|
||||
}
|
||||
|
||||
type RootCertificate x509.Certificate
|
||||
type ListenAddress string
|
||||
type Peer struct {
|
||||
URI string
|
||||
|
@ -34,6 +49,7 @@ type NodeInfo map[string]interface{}
|
|||
type NodeInfoPrivacy bool
|
||||
type AllowedPublicKey ed25519.PublicKey
|
||||
|
||||
func (a RootCertificate) isSetupOption() {}
|
||||
func (a ListenAddress) isSetupOption() {}
|
||||
func (a Peer) isSetupOption() {}
|
||||
func (a NodeInfo) isSetupOption() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue