|
@ -50,7 +50,7 @@ func TestRouter_Network(t *testing.T) { |
|
|
network := p2ptest.MakeNetwork(t, p2ptest.NetworkOptions{NumNodes: 8}) |
|
|
network := p2ptest.MakeNetwork(t, p2ptest.NetworkOptions{NumNodes: 8}) |
|
|
local := network.RandomNode() |
|
|
local := network.RandomNode() |
|
|
peers := network.Peers(local.NodeID) |
|
|
peers := network.Peers(local.NodeID) |
|
|
channels := network.MakeChannels(t, chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channels := network.MakeChannels(t, chDesc) |
|
|
|
|
|
|
|
|
network.Start(t) |
|
|
network.Start(t) |
|
|
|
|
|
|
|
@ -119,17 +119,18 @@ func TestRouter_Channel_Basic(t *testing.T) { |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
// Opening a channel should work.
|
|
|
// Opening a channel should work.
|
|
|
channel, err := router.OpenChannel(chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channel, err := router.OpenChannel(chDesc) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
require.Contains(t, router.NodeInfo().Channels, byte(chDesc.ID)) |
|
|
require.Contains(t, router.NodeInfo().Channels, byte(chDesc.ID)) |
|
|
|
|
|
|
|
|
// Opening the same channel again should fail.
|
|
|
// Opening the same channel again should fail.
|
|
|
_, err = router.OpenChannel(chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
_, err = router.OpenChannel(chDesc) |
|
|
require.Error(t, err) |
|
|
require.Error(t, err) |
|
|
|
|
|
|
|
|
// Opening a different channel should work.
|
|
|
// Opening a different channel should work.
|
|
|
chDesc2 := &p2p.ChannelDescriptor{ID: 2} |
|
|
|
|
|
_, err = router.OpenChannel(chDesc2, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
chDesc2 := &p2p.ChannelDescriptor{ID: 2, MessageType: &p2ptest.Message{}} |
|
|
|
|
|
_, err = router.OpenChannel(chDesc2) |
|
|
|
|
|
|
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
require.Contains(t, router.NodeInfo().Channels, byte(chDesc2.ID)) |
|
|
require.Contains(t, router.NodeInfo().Channels, byte(chDesc2.ID)) |
|
|
|
|
|
|
|
@ -137,7 +138,7 @@ func TestRouter_Channel_Basic(t *testing.T) { |
|
|
channel.Close() |
|
|
channel.Close() |
|
|
time.Sleep(100 * time.Millisecond) // yes yes, but Close() is async...
|
|
|
time.Sleep(100 * time.Millisecond) // yes yes, but Close() is async...
|
|
|
|
|
|
|
|
|
channel, err = router.OpenChannel(chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channel, err = router.OpenChannel(chDesc) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
// We should be able to send on the channel, even though there are no peers.
|
|
|
// We should be able to send on the channel, even though there are no peers.
|
|
@ -163,9 +164,9 @@ func TestRouter_Channel_SendReceive(t *testing.T) { |
|
|
|
|
|
|
|
|
ids := network.NodeIDs() |
|
|
ids := network.NodeIDs() |
|
|
aID, bID, cID := ids[0], ids[1], ids[2] |
|
|
aID, bID, cID := ids[0], ids[1], ids[2] |
|
|
channels := network.MakeChannels(t, chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channels := network.MakeChannels(t, chDesc) |
|
|
a, b, c := channels[aID], channels[bID], channels[cID] |
|
|
a, b, c := channels[aID], channels[bID], channels[cID] |
|
|
otherChannels := network.MakeChannels(t, p2ptest.MakeChannelDesc(9), &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
otherChannels := network.MakeChannels(t, p2ptest.MakeChannelDesc(9)) |
|
|
|
|
|
|
|
|
network.Start(t) |
|
|
network.Start(t) |
|
|
|
|
|
|
|
@ -222,7 +223,7 @@ func TestRouter_Channel_Broadcast(t *testing.T) { |
|
|
|
|
|
|
|
|
ids := network.NodeIDs() |
|
|
ids := network.NodeIDs() |
|
|
aID, bID, cID, dID := ids[0], ids[1], ids[2], ids[3] |
|
|
aID, bID, cID, dID := ids[0], ids[1], ids[2], ids[3] |
|
|
channels := network.MakeChannels(t, chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channels := network.MakeChannels(t, chDesc) |
|
|
a, b, c, d := channels[aID], channels[bID], channels[cID], channels[dID] |
|
|
a, b, c, d := channels[aID], channels[bID], channels[cID], channels[dID] |
|
|
|
|
|
|
|
|
network.Start(t) |
|
|
network.Start(t) |
|
@ -250,7 +251,15 @@ func TestRouter_Channel_Wrapper(t *testing.T) { |
|
|
|
|
|
|
|
|
ids := network.NodeIDs() |
|
|
ids := network.NodeIDs() |
|
|
aID, bID := ids[0], ids[1] |
|
|
aID, bID := ids[0], ids[1] |
|
|
channels := network.MakeChannels(t, chDesc, &wrapperMessage{}, 0) |
|
|
|
|
|
|
|
|
chDesc := &p2p.ChannelDescriptor{ |
|
|
|
|
|
ID: chID, |
|
|
|
|
|
MessageType: &wrapperMessage{}, |
|
|
|
|
|
Priority: 5, |
|
|
|
|
|
SendQueueCapacity: 10, |
|
|
|
|
|
RecvMessageCapacity: 10, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
channels := network.MakeChannels(t, chDesc) |
|
|
a, b := channels[aID], channels[bID] |
|
|
a, b := channels[aID], channels[bID] |
|
|
|
|
|
|
|
|
network.Start(t) |
|
|
network.Start(t) |
|
@ -310,7 +319,7 @@ func TestRouter_Channel_Error(t *testing.T) { |
|
|
|
|
|
|
|
|
ids := network.NodeIDs() |
|
|
ids := network.NodeIDs() |
|
|
aID, bID := ids[0], ids[1] |
|
|
aID, bID := ids[0], ids[1] |
|
|
channels := network.MakeChannels(t, chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channels := network.MakeChannels(t, chDesc) |
|
|
a := channels[aID] |
|
|
a := channels[aID] |
|
|
|
|
|
|
|
|
// Erroring b should cause it to be disconnected. It will reconnect shortly after.
|
|
|
// Erroring b should cause it to be disconnected. It will reconnect shortly after.
|
|
@ -897,7 +906,7 @@ func TestRouter_DontSendOnInvalidChannel(t *testing.T) { |
|
|
Status: p2p.PeerStatusUp, |
|
|
Status: p2p.PeerStatusUp, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
channel, err := router.OpenChannel(chDesc, &p2ptest.Message{}, 0) |
|
|
|
|
|
|
|
|
channel, err := router.OpenChannel(chDesc) |
|
|
require.NoError(t, err) |
|
|
require.NoError(t, err) |
|
|
|
|
|
|
|
|
channel.Out <- p2p.Envelope{ |
|
|
channel.Out <- p2p.Envelope{ |
|
|