github.com/yggdrasil-network/yggdrasil-go@v0.5.6/src/core/options.go (about) 1 package core 2 3 import ( 4 "crypto/ed25519" 5 "fmt" 6 "net/url" 7 ) 8 9 func (c *Core) _applyOption(opt SetupOption) (err error) { 10 switch v := opt.(type) { 11 case Peer: 12 u, err := url.Parse(v.URI) 13 if err != nil { 14 return fmt.Errorf("unable to parse peering URI: %w", err) 15 } 16 err = c.links.add(u, v.SourceInterface, linkTypePersistent) 17 switch err { 18 case ErrLinkAlreadyConfigured: 19 // Don't return this error, otherwise we'll panic at startup 20 // if there are multiple of the same peer configured 21 return nil 22 default: 23 return err 24 } 25 case ListenAddress: 26 c.config._listeners[v] = struct{}{} 27 case NodeInfo: 28 c.config.nodeinfo = v 29 case NodeInfoPrivacy: 30 c.config.nodeinfoPrivacy = v 31 case AllowedPublicKey: 32 pk := [32]byte{} 33 copy(pk[:], v) 34 c.config._allowedPublicKeys[pk] = struct{}{} 35 } 36 return 37 } 38 39 type SetupOption interface { 40 isSetupOption() 41 } 42 43 type ListenAddress string 44 type Peer struct { 45 URI string 46 SourceInterface string 47 } 48 type NodeInfo map[string]interface{} 49 type NodeInfoPrivacy bool 50 type AllowedPublicKey ed25519.PublicKey 51 52 func (a ListenAddress) isSetupOption() {} 53 func (a Peer) isSetupOption() {} 54 func (a NodeInfo) isSetupOption() {} 55 func (a NodeInfoPrivacy) isSetupOption() {} 56 func (a AllowedPublicKey) isSetupOption() {}