add -peer switch

This commit is contained in:
Neil Alexander 2020-06-09 16:12:48 +01:00
parent 512377d45b
commit 263fea7aed
2 changed files with 8 additions and 2 deletions

View file

@ -45,6 +45,7 @@ import (
var (
instanceName = flag.String("name", "dendrite-p2p-ygg", "the name of this P2P demo instance")
instancePort = flag.Int("port", 8008, "the port that the client API will listen on")
instancePeer = flag.String("peer", "", "an internet Yggdrasil peer to connect to")
)
type yggroundtripper struct {
@ -95,7 +96,7 @@ func main() {
},
}
ygg, err := yggconn.Setup(*instanceName)
ygg, err := yggconn.Setup(*instanceName, *instancePeer)
if err != nil {
panic(err)
}

View file

@ -32,7 +32,7 @@ type Node struct {
incoming chan *yamux.Stream
}
func Setup(instanceName string) (*Node, error) {
func Setup(instanceName, instancePeer string) (*Node, error) {
n := &Node{
core: &yggdrasil.Core{},
config: yggdrasilconfig.GenerateConfig(),
@ -71,6 +71,11 @@ func Setup(instanceName string) (*Node, error) {
if err != nil {
panic(err)
}
if instancePeer != "" {
if err = n.core.AddPeer(instancePeer, ""); err != nil {
panic(err)
}
}
if err = n.admin.Init(n.core, n.state, n.log, nil); err != nil {
panic(err)
}