mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2025-06-16 22:25:08 +03:00
More tweaking
This commit is contained in:
parent
15ce5ff319
commit
a4c80626f4
8 changed files with 25 additions and 42 deletions
|
@ -28,9 +28,9 @@ import (
|
|||
"github.com/yggdrasil-network/yggdrasil-go/src/admin"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
|
||||
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/core"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/tuntap"
|
||||
"github.com/yggdrasil-network/yggdrasil-go/src/version"
|
||||
|
@ -290,10 +290,7 @@ func run(args yggArgs, ctx context.Context, done chan struct{}) {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
options := []core.SetupOption{
|
||||
core.IfName(cfg.IfName),
|
||||
core.IfMTU(cfg.IfMTU),
|
||||
}
|
||||
options := []core.SetupOption{}
|
||||
for _, addr := range cfg.Listen {
|
||||
options = append(options, core.ListenAddress(addr))
|
||||
}
|
||||
|
|
|
@ -55,10 +55,7 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
|||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
options := []core.SetupOption{
|
||||
core.IfName("none"),
|
||||
core.IfMTU(m.config.IfMTU),
|
||||
}
|
||||
options := []core.SetupOption{}
|
||||
for _, peer := range m.config.Peers {
|
||||
options = append(options, core.Peer{URI: peer})
|
||||
}
|
||||
|
|
|
@ -40,8 +40,6 @@ type Core struct {
|
|||
_listeners map[ListenAddress]struct{} // configurable after startup
|
||||
nodeinfo NodeInfo // immutable after startup
|
||||
nodeinfoPrivacy NodeInfoPrivacy // immutable after startup
|
||||
ifname IfName // immutable after startup
|
||||
ifmtu IfMTU // immutable after startup
|
||||
_allowedPublicKeys map[[32]byte]struct{} // configurable after startup
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,10 +37,10 @@ func CreateAndConnectTwo(t testing.TB, verbose bool) (nodeA *Core, nodeB *Core)
|
|||
t.Fatal(err)
|
||||
}
|
||||
logger := GetLoggerWithPrefix("", false)
|
||||
if nodeA, err = New(skA, logger, ListenAddress("tcp://127.0.0.1:0"), IfName("none")); err != nil {
|
||||
if nodeA, err = New(skA, logger, ListenAddress("tcp://127.0.0.1:0")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if nodeB, err = New(skB, logger, ListenAddress("tcp://127.0.0.1:0"), IfName("none")); err != nil {
|
||||
if nodeB, err = New(skB, logger, ListenAddress("tcp://127.0.0.1:0")); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -81,17 +81,12 @@ func (l *links) init(c *Core) error {
|
|||
func (l *links) isConnectedTo(info linkInfo) bool {
|
||||
l.mutex.RLock()
|
||||
defer l.mutex.RUnlock()
|
||||
fmt.Println(l.links)
|
||||
_, isConnected := l.links[info]
|
||||
return isConnected
|
||||
}
|
||||
|
||||
func (l *links) call(u *url.URL, sintf string) error {
|
||||
info := linkInfo{
|
||||
linkType: strings.ToLower(u.Scheme),
|
||||
local: sintf,
|
||||
remote: u.Host,
|
||||
}
|
||||
info := linkInfoFor(u.Scheme, sintf, u.Host)
|
||||
if l.isConnectedTo(info) {
|
||||
return fmt.Errorf("already connected to this node")
|
||||
}
|
||||
|
@ -171,30 +166,30 @@ func (l *links) create(conn net.Conn, name string, info linkInfo, incoming, forc
|
|||
force: force,
|
||||
}
|
||||
go func() {
|
||||
if err := intf.handler(info); err != nil {
|
||||
if err := intf.handler(); err != nil {
|
||||
l.core.log.Errorf("Link handler error (%s): %s", conn.RemoteAddr(), err)
|
||||
}
|
||||
}()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (intf *link) handler(info linkInfo) error {
|
||||
func (intf *link) handler() error {
|
||||
defer intf.conn.Close()
|
||||
|
||||
// Don't connect to this link more than once.
|
||||
if intf.links.isConnectedTo(info) {
|
||||
return fmt.Errorf("already connected to %+v", info)
|
||||
if intf.links.isConnectedTo(intf.info) {
|
||||
return fmt.Errorf("already connected to %+v", intf.info)
|
||||
}
|
||||
|
||||
// Mark the connection as in progress.
|
||||
intf.links.mutex.Lock()
|
||||
intf.links.links[info] = nil
|
||||
intf.links.links[intf.info] = nil
|
||||
intf.links.mutex.Unlock()
|
||||
|
||||
// When we're done, clean up the connection entry.
|
||||
defer func() {
|
||||
intf.links.mutex.Lock()
|
||||
delete(intf.links.links, info)
|
||||
delete(intf.links.links, intf.info)
|
||||
intf.links.mutex.Unlock()
|
||||
}()
|
||||
|
||||
|
@ -275,7 +270,7 @@ func (intf *link) handler(info linkInfo) error {
|
|||
}
|
||||
|
||||
intf.links.mutex.Lock()
|
||||
intf.links.links[info] = intf
|
||||
intf.links.links[intf.info] = intf
|
||||
intf.links.mutex.Unlock()
|
||||
|
||||
remoteAddr := net.IP(address.AddrForKey(meta.key)[:]).String()
|
||||
|
@ -304,13 +299,13 @@ func (intf *link) name() string {
|
|||
return intf.lname
|
||||
}
|
||||
|
||||
func linkInfoFor(linkType, local, remote string) linkInfo {
|
||||
func linkInfoFor(linkType, sintf, remote string) linkInfo {
|
||||
if h, _, err := net.SplitHostPort(remote); err == nil {
|
||||
remote = h
|
||||
}
|
||||
return linkInfo{
|
||||
linkType: linkType,
|
||||
local: local,
|
||||
local: sintf,
|
||||
remote: remote,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Arceliar/phony"
|
||||
|
@ -39,7 +40,7 @@ func (l *links) newLinkTCP() *linkTCP {
|
|||
}
|
||||
|
||||
func (l *linkTCP) dial(url *url.URL, options tcpOptions, sintf string) error {
|
||||
info := linkInfoFor("tcp", url.Host, sintf)
|
||||
info := linkInfoFor("tcp", sintf, strings.SplitN(url.Host, "%", 2)[0])
|
||||
if l.links.isConnectedTo(info) {
|
||||
return fmt.Errorf("duplicate connection attempt")
|
||||
}
|
||||
|
@ -86,8 +87,9 @@ func (l *linkTCP) listen(url *url.URL, sintf string) (*Listener, error) {
|
|||
cancel()
|
||||
return
|
||||
}
|
||||
name := fmt.Sprintf("tcp://%s", conn.RemoteAddr())
|
||||
info := linkInfoFor("tcp", sintf, conn.RemoteAddr().String())
|
||||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||
name := fmt.Sprintf("tls://%s", addr)
|
||||
info := linkInfoFor("tcp", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
||||
if err = l.handler(name, info, conn, tcpOptions{}, true); err != nil {
|
||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import (
|
|||
"math/big"
|
||||
"net"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/Arceliar/phony"
|
||||
|
@ -46,7 +47,7 @@ func (l *links) newLinkTLS(tcp *linkTCP) *linkTLS {
|
|||
}
|
||||
|
||||
func (l *linkTLS) dial(url *url.URL, options tcpOptions, sintf string) error {
|
||||
info := linkInfoFor("tls", url.Host, sintf)
|
||||
info := linkInfoFor("tls", sintf, strings.SplitN(url.Host, "%", 2)[0])
|
||||
if l.links.isConnectedTo(info) {
|
||||
return fmt.Errorf("duplicate connection attempt")
|
||||
}
|
||||
|
@ -98,8 +99,9 @@ func (l *linkTLS) listen(url *url.URL, sintf string) (*Listener, error) {
|
|||
cancel()
|
||||
return
|
||||
}
|
||||
name := fmt.Sprintf("tls://%s", conn.RemoteAddr())
|
||||
info := linkInfoFor("tls", sintf, conn.RemoteAddr().String())
|
||||
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||
name := fmt.Sprintf("tls://%s", addr)
|
||||
info := linkInfoFor("tls", sintf, strings.SplitN(addr.IP.String(), "%", 2)[0])
|
||||
if err = l.handler(name, info, conn, tcpOptions{}, true); err != nil {
|
||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||
}
|
||||
|
|
|
@ -14,10 +14,6 @@ func (c *Core) _applyOption(opt SetupOption) {
|
|||
c.config.nodeinfo = v
|
||||
case NodeInfoPrivacy:
|
||||
c.config.nodeinfoPrivacy = v
|
||||
case IfName:
|
||||
c.config.ifname = v
|
||||
case IfMTU:
|
||||
c.config.ifmtu = v
|
||||
case AllowedPublicKey:
|
||||
pk := [32]byte{}
|
||||
copy(pk[:], v)
|
||||
|
@ -36,14 +32,10 @@ type Peer struct {
|
|||
}
|
||||
type NodeInfo map[string]interface{}
|
||||
type NodeInfoPrivacy bool
|
||||
type IfName string
|
||||
type IfMTU uint16
|
||||
type AllowedPublicKey ed25519.PublicKey
|
||||
|
||||
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() {}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue