mirror of
https://github.com/neilalexander/yggmail.git
synced 2026-05-22 19:16:29 +03:00
Fix Yggdrasil v0.4.5 build
This commit is contained in:
@@ -14,12 +14,12 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
|
"regexp"
|
||||||
|
|
||||||
iwt "github.com/Arceliar/ironwood/types"
|
iwt "github.com/Arceliar/ironwood/types"
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
gologme "github.com/gologme/log"
|
gologme "github.com/gologme/log"
|
||||||
"github.com/neilalexander/utp"
|
"github.com/neilalexander/utp"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
||||||
)
|
)
|
||||||
@@ -29,42 +29,46 @@ type YggdrasilTransport struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.PublicKey, peers []string, mcast bool) (*YggdrasilTransport, error) {
|
func NewYggdrasilTransport(log *log.Logger, sk ed25519.PrivateKey, pk ed25519.PublicKey, peers []string, mcast bool) (*YggdrasilTransport, error) {
|
||||||
config := &config.NodeConfig{
|
|
||||||
PublicKey: hex.EncodeToString(pk),
|
|
||||||
PrivateKey: hex.EncodeToString(sk),
|
|
||||||
Peers: peers,
|
|
||||||
MulticastInterfaces: []config.MulticastInterfaceConfig{
|
|
||||||
{
|
|
||||||
Regex: ".*",
|
|
||||||
Beacon: true,
|
|
||||||
Listen: true,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
NodeInfo: map[string]interface{}{
|
|
||||||
"name": hex.EncodeToString(pk) + "@yggmail",
|
|
||||||
},
|
|
||||||
NodeInfoPrivacy: true,
|
|
||||||
}
|
|
||||||
yellow := color.New(color.FgYellow).SprintfFunc()
|
yellow := color.New(color.FgYellow).SprintfFunc()
|
||||||
glog := gologme.New(log.Writer(), fmt.Sprintf("[ %s ] ", yellow("Yggdrasil")), gologme.LstdFlags|gologme.Lmsgprefix)
|
glog := gologme.New(log.Writer(), fmt.Sprintf("[ %s ] ", yellow("Yggdrasil")), gologme.LstdFlags|gologme.Lmsgprefix)
|
||||||
glog.EnableLevel("warn")
|
glog.EnableLevel("warn")
|
||||||
glog.EnableLevel("error")
|
glog.EnableLevel("error")
|
||||||
glog.EnableLevel("info")
|
glog.EnableLevel("info")
|
||||||
|
|
||||||
core := &core.Core{}
|
var ygg *core.Core
|
||||||
if err := core.Start(config, glog); err != nil {
|
var err error
|
||||||
return nil, fmt.Errorf("core.Start: %w", err)
|
|
||||||
}
|
// Setup the Yggdrasil node itself.
|
||||||
if mcast {
|
{
|
||||||
multicast := &multicast.Multicast{}
|
options := []core.SetupOption{
|
||||||
if err := multicast.Init(core, config, glog, nil); err != nil {
|
core.NodeInfo(map[string]interface{}{
|
||||||
return nil, fmt.Errorf("multicast.Init: %w", err)
|
"name": hex.EncodeToString(pk) + "@yggmail",
|
||||||
|
}),
|
||||||
|
core.NodeInfoPrivacy(true),
|
||||||
}
|
}
|
||||||
if err := multicast.Start(); err != nil {
|
for _, peer := range peers {
|
||||||
return nil, fmt.Errorf("multicast.Start: %w", err)
|
options = append(options, core.Peer{URI: peer})
|
||||||
|
}
|
||||||
|
if ygg, err = core.New(sk[:], glog, options...); err != nil {
|
||||||
|
panic(err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
us, err := utp.NewSocketFromPacketConnNoClose(core)
|
|
||||||
|
// Setup the multicast module.
|
||||||
|
{
|
||||||
|
options := []multicast.SetupOption{
|
||||||
|
multicast.MulticastInterface{
|
||||||
|
Regex: regexp.MustCompile(".*"),
|
||||||
|
Beacon: true,
|
||||||
|
Listen: true,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
if _, err = multicast.New(ygg, glog, options...); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
us, err := utp.NewSocketFromPacketConnNoClose(ygg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("utp.NewSocketFromPacketConnNoClose: %w", err)
|
return nil, fmt.Errorf("utp.NewSocketFromPacketConnNoClose: %w", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user