Refactor multicast setup (isolated config, etc)

This commit is contained in:
Neil Alexander 2022-09-03 11:42:05 +01:00
parent dad0b10dfe
commit 493208fb37
10 changed files with 215 additions and 150 deletions

View file

@ -15,8 +15,8 @@ import (
//"sort"
//"time"
"github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/address"
"github.com/yggdrasil-network/yggdrasil-go/src/util"
//"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
//"github.com/Arceliar/phony"
)
@ -159,7 +159,7 @@ func (c *Core) Subnet() net.IPNet {
// may be useful if you want to redirect the output later. Note that this
// expects a Logger from the github.com/gologme/log package and not from Go's
// built-in log package.
func (c *Core) SetLogger(log *log.Logger) {
func (c *Core) SetLogger(log util.Logger) {
c.log = log
}
@ -239,8 +239,10 @@ func (c *Core) RemovePeer(addr string, sintf string) error {
// CallPeer calls a peer once. This should be specified in the peer URI format,
// e.g.:
// tcp://a.b.c.d:e
// socks://a.b.c.d:e/f.g.h.i:j
//
// tcp://a.b.c.d:e
// socks://a.b.c.d:e/f.g.h.i:j
//
// This does not add the peer to the peer list, so if the connection drops, the
// peer will not be called again automatically.
func (c *Core) CallPeer(u *url.URL, sintf string) error {

View file

@ -7,7 +7,6 @@ import (
"io"
"net"
"net/url"
"os"
"time"
iwe "github.com/Arceliar/ironwood/encrypted"
@ -15,6 +14,7 @@ import (
"github.com/Arceliar/phony"
"github.com/gologme/log"
"github.com/yggdrasil-network/yggdrasil-go/src/util"
"github.com/yggdrasil-network/yggdrasil-go/src/version"
//"github.com/yggdrasil-network/yggdrasil-go/src/crypto"
)
@ -33,7 +33,7 @@ type Core struct {
public ed25519.PublicKey
links links
proto protoHandler
log *log.Logger
log util.Logger
addPeerTimer *time.Timer
config struct {
_peers map[Peer]struct{} // configurable after startup
@ -46,14 +46,14 @@ type Core struct {
}
}
func New(secret ed25519.PrivateKey, opts ...SetupOption) (*Core, error) {
func New(secret ed25519.PrivateKey, logger util.Logger, opts ...SetupOption) (*Core, error) {
if len(secret) != ed25519.PrivateKeySize {
return nil, fmt.Errorf("private key is incorrect length")
}
c := &Core{
secret: secret,
public: secret.Public().(ed25519.PublicKey),
log: log.New(os.Stdout, "", 0), // TODO: not this
log: logger,
}
c.ctx, c.cancel = context.WithCancel(context.Background())
var err error

View file

@ -36,10 +36,11 @@ func CreateAndConnectTwo(t testing.TB, verbose bool) (nodeA *Core, nodeB *Core)
if _, skB, err = ed25519.GenerateKey(nil); err != nil {
t.Fatal(err)
}
if nodeA, err = New(skA, ListenAddress("tcp://127.0.0.1:0"), IfName("none")); err != nil {
logger := GetLoggerWithPrefix("", false)
if nodeA, err = New(skA, logger, ListenAddress("tcp://127.0.0.1:0"), IfName("none")); err != nil {
t.Fatal(err)
}
if nodeB, err = New(skB, ListenAddress("tcp://127.0.0.1:0"), IfName("none")); err != nil {
if nodeB, err = New(skB, logger, ListenAddress("tcp://127.0.0.1:0"), IfName("none")); err != nil {
t.Fatal(err)
}

View file

@ -30,7 +30,6 @@ type SetupOption interface {
}
type ListenAddress string
type AdminListenAddress string
type Peer struct {
URI string
SourceInterface string
@ -41,11 +40,10 @@ type IfName string
type IfMTU uint16
type AllowedPublicKey ed25519.PublicKey
func (a ListenAddress) isSetupOption() {}
func (a AdminListenAddress) isSetupOption() {}
func (a Peer) isSetupOption() {}
func (a NodeInfo) isSetupOption() {}
func (a NodeInfoPrivacy) isSetupOption() {}
func (a IfName) isSetupOption() {}
func (a IfMTU) isSetupOption() {}
func (a AllowedPublicKey) isSetupOption() {}
func (a ListenAddress) isSetupOption() {}
func (a Peer) isSetupOption() {}
func (a NodeInfo) isSetupOption() {}
func (a NodeInfoPrivacy) isSetupOption() {}
func (a IfName) isSetupOption() {}
func (a IfMTU) isSetupOption() {}
func (a AllowedPublicKey) isSetupOption() {}