2018-03-29 03:27:48 +00:00
|
|
|
package torrent
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestBep40Priority(t *testing.T) {
|
2018-04-14 11:43:08 +00:00
|
|
|
assert.EqualValues(t, 0xec2d7224, bep40PriorityIgnoreError(
|
2018-11-15 23:35:30 +00:00
|
|
|
IpPort{net.ParseIP("123.213.32.10"), 0},
|
|
|
|
IpPort{net.ParseIP("98.76.54.32"), 0},
|
2018-03-29 03:27:48 +00:00
|
|
|
))
|
2018-04-14 11:43:08 +00:00
|
|
|
assert.EqualValues(t, 0xec2d7224, bep40PriorityIgnoreError(
|
2018-11-15 23:35:30 +00:00
|
|
|
IpPort{net.ParseIP("98.76.54.32"), 0},
|
|
|
|
IpPort{net.ParseIP("123.213.32.10"), 0},
|
2018-03-29 03:27:48 +00:00
|
|
|
))
|
2018-04-14 11:43:08 +00:00
|
|
|
assert.Equal(t, peerPriority(0x99568189), bep40PriorityIgnoreError(
|
2018-11-15 23:35:30 +00:00
|
|
|
IpPort{net.ParseIP("123.213.32.10"), 0},
|
|
|
|
IpPort{net.ParseIP("123.213.32.234"), 0},
|
2018-03-29 03:27:48 +00:00
|
|
|
))
|
2018-04-14 11:43:08 +00:00
|
|
|
assert.EqualValues(t, "\x00\x00\x00\x00", func() []byte {
|
|
|
|
b, _ := bep40PriorityBytes(
|
2018-11-15 23:35:30 +00:00
|
|
|
IpPort{net.ParseIP("123.213.32.234"), 0},
|
|
|
|
IpPort{net.ParseIP("123.213.32.234"), 0},
|
2018-04-14 11:43:08 +00:00
|
|
|
)
|
|
|
|
return b
|
|
|
|
}())
|
2018-03-29 03:27:48 +00:00
|
|
|
}
|