From a9ec3877b5ff4619031a6995b3ac8eff436081a2 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Sun, 14 May 2023 15:59:52 +0100 Subject: [PATCH] Fix unit test --- src/core/core_test.go | 16 ++++++++++++---- src/core/link_tcp.go | 14 -------------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/src/core/core_test.go b/src/core/core_test.go index 49901324..c38a750a 100644 --- a/src/core/core_test.go +++ b/src/core/core_test.go @@ -39,22 +39,30 @@ func CreateAndConnectTwo(t testing.TB, verbose bool) (nodeA *Core, nodeB *Core) } logger := GetLoggerWithPrefix("", false) + logger.EnableLevel("debug") - if nodeA, err = New(cfgA.Certificate, logger, ListenAddress("tcp://127.0.0.1:0")); err != nil { + if nodeA, err = New(cfgA.Certificate, logger); err != nil { t.Fatal(err) } - if nodeB, err = New(cfgB.Certificate, logger, ListenAddress("tcp://127.0.0.1:0")); err != nil { + if nodeB, err = New(cfgB.Certificate, logger); err != nil { t.Fatal(err) } - u, err := url.Parse("tcp://" + nodeA.links.tcp.getAddr().String()) + nodeAListenURL, err := url.Parse("tcp://localhost:0") if err != nil { t.Fatal(err) } - err = nodeB.CallPeer(u, "") + nodeAListener, err := nodeA.Listen(nodeAListenURL, "") if err != nil { t.Fatal(err) } + nodeAURL, err := url.Parse("tcp://" + nodeAListener.Addr().String()) + if err != nil { + t.Fatal(err) + } + if err = nodeB.CallPeer(nodeAURL, ""); err != nil { + t.Fatal(err) + } time.Sleep(100 * time.Millisecond) diff --git a/src/core/link_tcp.go b/src/core/link_tcp.go index e2e51c35..8ffb3124 100644 --- a/src/core/link_tcp.go +++ b/src/core/link_tcp.go @@ -104,20 +104,6 @@ func (l *linkTCP) listen(ctx context.Context, url *url.URL, sintf string) (net.L return l.listenconfig.Listen(ctx, "tcp", hostport) } -// Returns the address of the listener. -func (l *linkTCP) getAddr() *net.TCPAddr { - // TODO: Fix this, because this will currently only give a single address - // to multicast.go, which obviously is not great, but right now multicast.go - // doesn't have the ability to send more than one address in a packet either - var addr *net.TCPAddr - phony.Block(l, func() { - for li := range l._listeners { - addr = li.listener.Addr().(*net.TCPAddr) - } - }) - return addr -} - func (l *linkTCP) dialerFor(dst *net.TCPAddr, sintf string) (*net.Dialer, error) { if dst.IP.IsLinkLocalUnicast() { if sintf != "" {