mirror of
https://github.com/luxfi/node.git
synced 2026-10-30 15:24:05 +00:00
Two packages were named for the same word and meant different things. network/ dialed peers, exchanged keys, throttled and tracked them; nets/ tracked which chains share a validator set and when they have all bootstrapped. One letter apart, and neither name said which was which. The peer layer is mesh — the word this estate already uses for it, in lux-rs/node's own mesh.rs. That frees network for the thing that is actually a network: a set of chains sharing a validator set. A network holds chains; a chain belongs to one network. github.com/luxfi/p2p stays what it is, the gossip library the VMs use. Three concerns, three names, none of them borrowed from another. Co-authored-by: Hanzo Dev <[email protected]>
63 lines
1.3 KiB
Go
63 lines
1.3 KiB
Go
// Copyright (C) 2019-2025, Lux Industries Inc. All rights reserved.
|
|
// See the file LICENSE for licensing terms.
|
|
|
|
package dialer
|
|
|
|
import (
|
|
"context"
|
|
"net"
|
|
"net/netip"
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
"golang.org/x/sync/errgroup"
|
|
|
|
"github.com/luxfi/log"
|
|
)
|
|
|
|
// Test that canceling a context passed into Dial results
|
|
// in giving up trying to connect
|
|
func TestDialerDialCanceledContext(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
listenAddrPort := netip.AddrPortFrom(netip.IPv4Unspecified(), 0)
|
|
dialer := NewDialer("tcp", Config{}, log.NewNoOpLogger())
|
|
|
|
ctx, cancel := context.WithCancel(context.Background())
|
|
cancel()
|
|
_, err := dialer.Dial(ctx, listenAddrPort)
|
|
require.ErrorIs(err, context.Canceled)
|
|
}
|
|
|
|
func TestDialerDial(t *testing.T) {
|
|
require := require.New(t)
|
|
|
|
l, err := net.Listen("tcp", "127.0.0.1:0")
|
|
require.NoError(err)
|
|
|
|
listenedAddrPort, err := netip.ParseAddrPort(l.Addr().String())
|
|
require.NoError(err)
|
|
|
|
dialer := NewDialer(
|
|
"tcp",
|
|
Config{
|
|
ThrottleRps: 10,
|
|
ConnectionTimeout: 30 * time.Second,
|
|
},
|
|
log.NewNoOpLogger(),
|
|
)
|
|
|
|
eg := errgroup.Group{}
|
|
eg.Go(func() error {
|
|
_, err := dialer.Dial(context.Background(), listenedAddrPort)
|
|
return err
|
|
})
|
|
|
|
_, err = l.Accept()
|
|
require.NoError(err)
|
|
|
|
require.NoError(eg.Wait())
|
|
require.NoError(l.Close())
|
|
}
|