2018-07-10 01:21:24 +00:00
|
|
|
package peer_protocol
|
2015-08-17 09:52:47 +00:00
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-11-02 12:12:01 +00:00
|
|
|
"github.com/stretchr/testify/require"
|
2019-08-21 10:58:40 +00:00
|
|
|
|
|
|
|
"github.com/anacrolix/torrent/bencode"
|
2015-08-17 09:52:47 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestUnmarshalPex(t *testing.T) {
|
2018-07-10 01:21:24 +00:00
|
|
|
var pem PexMsg
|
2015-08-17 09:52:47 +00:00
|
|
|
err := bencode.Unmarshal([]byte("d5:added12:\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0ce"), &pem)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.EqualValues(t, 2, len(pem.Added))
|
|
|
|
require.EqualValues(t, 1286, pem.Added[0].Port)
|
|
|
|
require.EqualValues(t, 0x100*0xb+0xc, pem.Added[1].Port)
|
|
|
|
}
|
2018-11-26 21:57:17 +00:00
|
|
|
|
|
|
|
func TestEmptyPexMsg(t *testing.T) {
|
|
|
|
pm := PexMsg{}
|
|
|
|
b, err := bencode.Marshal(pm)
|
|
|
|
t.Logf("%q", b)
|
|
|
|
require.NoError(t, err)
|
|
|
|
require.NoError(t, bencode.Unmarshal(b, &pm))
|
|
|
|
}
|