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/admin"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
"github.com/yggdrasil-network/yggdrasil-go/src/config"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/defaults"
|
"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/core"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/ipv6rwc"
|
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
"github.com/yggdrasil-network/yggdrasil-go/src/multicast"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/tuntap"
|
"github.com/yggdrasil-network/yggdrasil-go/src/tuntap"
|
||||||
"github.com/yggdrasil-network/yggdrasil-go/src/version"
|
"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 {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
options := []core.SetupOption{
|
options := []core.SetupOption{}
|
||||||
core.IfName(cfg.IfName),
|
|
||||||
core.IfMTU(cfg.IfMTU),
|
|
||||||
}
|
|
||||||
for _, addr := range cfg.Listen {
|
for _, addr := range cfg.Listen {
|
||||||
options = append(options, core.ListenAddress(addr))
|
options = append(options, core.ListenAddress(addr))
|
||||||
}
|
}
|
||||||
|
|
|
@ -55,10 +55,7 @@ func (m *Yggdrasil) StartJSON(configjson []byte) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
options := []core.SetupOption{
|
options := []core.SetupOption{}
|
||||||
core.IfName("none"),
|
|
||||||
core.IfMTU(m.config.IfMTU),
|
|
||||||
}
|
|
||||||
for _, peer := range m.config.Peers {
|
for _, peer := range m.config.Peers {
|
||||||
options = append(options, core.Peer{URI: peer})
|
options = append(options, core.Peer{URI: peer})
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,8 +40,6 @@ type Core struct {
|
||||||
_listeners map[ListenAddress]struct{} // configurable after startup
|
_listeners map[ListenAddress]struct{} // configurable after startup
|
||||||
nodeinfo NodeInfo // immutable after startup
|
nodeinfo NodeInfo // immutable after startup
|
||||||
nodeinfoPrivacy NodeInfoPrivacy // 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
|
_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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
logger := GetLoggerWithPrefix("", false)
|
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)
|
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)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -81,17 +81,12 @@ func (l *links) init(c *Core) error {
|
||||||
func (l *links) isConnectedTo(info linkInfo) bool {
|
func (l *links) isConnectedTo(info linkInfo) bool {
|
||||||
l.mutex.RLock()
|
l.mutex.RLock()
|
||||||
defer l.mutex.RUnlock()
|
defer l.mutex.RUnlock()
|
||||||
fmt.Println(l.links)
|
|
||||||
_, isConnected := l.links[info]
|
_, isConnected := l.links[info]
|
||||||
return isConnected
|
return isConnected
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *links) call(u *url.URL, sintf string) error {
|
func (l *links) call(u *url.URL, sintf string) error {
|
||||||
info := linkInfo{
|
info := linkInfoFor(u.Scheme, sintf, u.Host)
|
||||||
linkType: strings.ToLower(u.Scheme),
|
|
||||||
local: sintf,
|
|
||||||
remote: u.Host,
|
|
||||||
}
|
|
||||||
if l.isConnectedTo(info) {
|
if l.isConnectedTo(info) {
|
||||||
return fmt.Errorf("already connected to this node")
|
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,
|
force: force,
|
||||||
}
|
}
|
||||||
go func() {
|
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)
|
l.core.log.Errorf("Link handler error (%s): %s", conn.RemoteAddr(), err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (intf *link) handler(info linkInfo) error {
|
func (intf *link) handler() error {
|
||||||
defer intf.conn.Close()
|
defer intf.conn.Close()
|
||||||
|
|
||||||
// Don't connect to this link more than once.
|
// Don't connect to this link more than once.
|
||||||
if intf.links.isConnectedTo(info) {
|
if intf.links.isConnectedTo(intf.info) {
|
||||||
return fmt.Errorf("already connected to %+v", info)
|
return fmt.Errorf("already connected to %+v", intf.info)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mark the connection as in progress.
|
// Mark the connection as in progress.
|
||||||
intf.links.mutex.Lock()
|
intf.links.mutex.Lock()
|
||||||
intf.links.links[info] = nil
|
intf.links.links[intf.info] = nil
|
||||||
intf.links.mutex.Unlock()
|
intf.links.mutex.Unlock()
|
||||||
|
|
||||||
// When we're done, clean up the connection entry.
|
// When we're done, clean up the connection entry.
|
||||||
defer func() {
|
defer func() {
|
||||||
intf.links.mutex.Lock()
|
intf.links.mutex.Lock()
|
||||||
delete(intf.links.links, info)
|
delete(intf.links.links, intf.info)
|
||||||
intf.links.mutex.Unlock()
|
intf.links.mutex.Unlock()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -275,7 +270,7 @@ func (intf *link) handler(info linkInfo) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
intf.links.mutex.Lock()
|
intf.links.mutex.Lock()
|
||||||
intf.links.links[info] = intf
|
intf.links.links[intf.info] = intf
|
||||||
intf.links.mutex.Unlock()
|
intf.links.mutex.Unlock()
|
||||||
|
|
||||||
remoteAddr := net.IP(address.AddrForKey(meta.key)[:]).String()
|
remoteAddr := net.IP(address.AddrForKey(meta.key)[:]).String()
|
||||||
|
@ -304,13 +299,13 @@ func (intf *link) name() string {
|
||||||
return intf.lname
|
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 {
|
if h, _, err := net.SplitHostPort(remote); err == nil {
|
||||||
remote = h
|
remote = h
|
||||||
}
|
}
|
||||||
return linkInfo{
|
return linkInfo{
|
||||||
linkType: linkType,
|
linkType: linkType,
|
||||||
local: local,
|
local: sintf,
|
||||||
remote: remote,
|
remote: remote,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Arceliar/phony"
|
"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 {
|
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) {
|
if l.links.isConnectedTo(info) {
|
||||||
return fmt.Errorf("duplicate connection attempt")
|
return fmt.Errorf("duplicate connection attempt")
|
||||||
}
|
}
|
||||||
|
@ -86,8 +87,9 @@ func (l *linkTCP) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("tcp://%s", conn.RemoteAddr())
|
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||||
info := linkInfoFor("tcp", sintf, conn.RemoteAddr().String())
|
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 {
|
if err = l.handler(name, info, conn, tcpOptions{}, true); err != nil {
|
||||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import (
|
||||||
"math/big"
|
"math/big"
|
||||||
"net"
|
"net"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Arceliar/phony"
|
"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 {
|
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) {
|
if l.links.isConnectedTo(info) {
|
||||||
return fmt.Errorf("duplicate connection attempt")
|
return fmt.Errorf("duplicate connection attempt")
|
||||||
}
|
}
|
||||||
|
@ -98,8 +99,9 @@ func (l *linkTLS) listen(url *url.URL, sintf string) (*Listener, error) {
|
||||||
cancel()
|
cancel()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
name := fmt.Sprintf("tls://%s", conn.RemoteAddr())
|
addr := conn.RemoteAddr().(*net.TCPAddr)
|
||||||
info := linkInfoFor("tls", sintf, conn.RemoteAddr().String())
|
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 {
|
if err = l.handler(name, info, conn, tcpOptions{}, true); err != nil {
|
||||||
l.core.log.Errorln("Failed to create inbound link:", err)
|
l.core.log.Errorln("Failed to create inbound link:", err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,6 @@ func (c *Core) _applyOption(opt SetupOption) {
|
||||||
c.config.nodeinfo = v
|
c.config.nodeinfo = v
|
||||||
case NodeInfoPrivacy:
|
case NodeInfoPrivacy:
|
||||||
c.config.nodeinfoPrivacy = v
|
c.config.nodeinfoPrivacy = v
|
||||||
case IfName:
|
|
||||||
c.config.ifname = v
|
|
||||||
case IfMTU:
|
|
||||||
c.config.ifmtu = v
|
|
||||||
case AllowedPublicKey:
|
case AllowedPublicKey:
|
||||||
pk := [32]byte{}
|
pk := [32]byte{}
|
||||||
copy(pk[:], v)
|
copy(pk[:], v)
|
||||||
|
@ -36,14 +32,10 @@ type Peer struct {
|
||||||
}
|
}
|
||||||
type NodeInfo map[string]interface{}
|
type NodeInfo map[string]interface{}
|
||||||
type NodeInfoPrivacy bool
|
type NodeInfoPrivacy bool
|
||||||
type IfName string
|
|
||||||
type IfMTU uint16
|
|
||||||
type AllowedPublicKey ed25519.PublicKey
|
type AllowedPublicKey ed25519.PublicKey
|
||||||
|
|
||||||
func (a ListenAddress) isSetupOption() {}
|
func (a ListenAddress) isSetupOption() {}
|
||||||
func (a Peer) isSetupOption() {}
|
func (a Peer) isSetupOption() {}
|
||||||
func (a NodeInfo) isSetupOption() {}
|
func (a NodeInfo) isSetupOption() {}
|
||||||
func (a NodeInfoPrivacy) isSetupOption() {}
|
func (a NodeInfoPrivacy) isSetupOption() {}
|
||||||
func (a IfName) isSetupOption() {}
|
|
||||||
func (a IfMTU) isSetupOption() {}
|
|
||||||
func (a AllowedPublicKey) isSetupOption() {}
|
func (a AllowedPublicKey) isSetupOption() {}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue