mirror of
https://github.com/yggdrasil-network/yggdrasil-go.git
synced 2026-05-22 13:56:30 +03:00
@@ -158,6 +158,9 @@ const ErrLinkNoSuitableIPs = linkError("peer has no suitable addresses")
|
|||||||
const ErrLinkToSelf = linkError("node cannot connect to self")
|
const ErrLinkToSelf = linkError("node cannot connect to self")
|
||||||
|
|
||||||
func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
|
func (l *links) add(u *url.URL, sintf string, linkType linkType) error {
|
||||||
|
if _, err := l.dialerFor(u); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
var retErr error
|
var retErr error
|
||||||
phony.Block(l, func() {
|
phony.Block(l, func() {
|
||||||
// Generate the link info and see whether we think we already
|
// Generate the link info and see whether we think we already
|
||||||
@@ -591,6 +594,14 @@ func (l *links) listen(u *url.URL, sintf string, local bool) (*Listener, error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (l *links) connect(ctx context.Context, u *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
|
func (l *links) connect(ctx context.Context, u *url.URL, info linkInfo, options linkOptions) (net.Conn, error) {
|
||||||
|
dialer, err := l.dialerFor(u)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return dialer.dial(ctx, u, info, options)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *links) dialerFor(u *url.URL) (linkProtocol, error) {
|
||||||
var dialer linkProtocol
|
var dialer linkProtocol
|
||||||
switch strings.ToLower(u.Scheme) {
|
switch strings.ToLower(u.Scheme) {
|
||||||
case "tcp":
|
case "tcp":
|
||||||
@@ -610,7 +621,7 @@ func (l *links) connect(ctx context.Context, u *url.URL, info linkInfo, options
|
|||||||
default:
|
default:
|
||||||
return nil, ErrLinkUnrecognisedSchema
|
return nil, ErrLinkUnrecognisedSchema
|
||||||
}
|
}
|
||||||
return dialer.dial(ctx, u, info, options)
|
return dialer, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn, success func(), local bool) error {
|
func (l *links) handler(linkType linkType, options linkOptions, conn net.Conn, success func(), local bool) error {
|
||||||
|
|||||||
@@ -39,3 +39,15 @@ func TestDuplicatePeerFromAPI(t *testing.T) {
|
|||||||
t.Fatalf("Adding peer should have failed on second attempt")
|
t.Fatalf("Adding peer should have failed on second attempt")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestAddEmptyPeer(t *testing.T) {
|
||||||
|
cfg := config.GenerateConfig()
|
||||||
|
c, err := New(cfg.Certificate, nil)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatal(err)
|
||||||
|
}
|
||||||
|
u, _ := url.Parse("")
|
||||||
|
if err := c.AddPeer(u, ""); err == nil {
|
||||||
|
t.Fatalf("Expected error on empty URL: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user