FedP2P/bep40_test.go

35 lines
1.0 KiB
Go
Raw Normal View History

2018-03-29 11:27:48 +08:00
package torrent
import (
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func TestBep40Priority(t *testing.T) {
2019-07-26 08:56:13 +08:00
assert.EqualValues(t, peerPriority(0xec2d7224), bep40PriorityIgnoreError(
2020-01-13 03:26:29 +08:00
IpPort{IP: net.ParseIP("123.213.32.10"), Port: 0},
IpPort{IP: net.ParseIP("98.76.54.32"), Port: 0},
2018-03-29 11:27:48 +08:00
))
2019-07-26 08:56:13 +08:00
assert.EqualValues(t, peerPriority(0xec2d7224), bep40PriorityIgnoreError(
2020-01-13 03:26:29 +08:00
IpPort{IP: net.ParseIP("98.76.54.32"), Port: 0},
IpPort{IP: net.ParseIP("123.213.32.10"), Port: 0},
2018-03-29 11:27:48 +08:00
))
2018-04-14 19:43:08 +08:00
assert.Equal(t, peerPriority(0x99568189), bep40PriorityIgnoreError(
2020-01-13 03:26:29 +08:00
IpPort{IP: net.ParseIP("123.213.32.10"), Port: 0},
IpPort{IP: net.ParseIP("123.213.32.234"), Port: 0},
2018-03-29 11:27:48 +08:00
))
assert.Equal(t, peerPriority(0x2b41d456), bep40PriorityIgnoreError(
IpPort{IP: net.ParseIP("206.248.98.111"), Port: 0},
IpPort{IP: net.ParseIP("142.147.89.224"), Port: 0},
))
2018-04-14 19:43:08 +08:00
assert.EqualValues(t, "\x00\x00\x00\x00", func() []byte {
b, _ := bep40PriorityBytes(
2020-01-13 03:26:29 +08:00
IpPort{IP: net.ParseIP("123.213.32.234"), Port: 0},
IpPort{IP: net.ParseIP("123.213.32.234"), Port: 0},
2018-04-14 19:43:08 +08:00
)
return b
}())
2018-03-29 11:27:48 +08:00
}