2016-12-28 22:47:52 +00:00
|
|
|
package tunnel
|
|
|
|
|
|
|
|
import (
|
2021-04-19 20:43:37 -04:00
|
|
|
"github.com/go-i2p/go-i2p/lib/common"
|
2016-12-28 22:47:52 +00:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"testing"
|
|
|
|
)
|
|
|
|
|
|
|
|
type DeliveryInstructionsFlags struct {
|
|
|
|
FirstFragment bool
|
|
|
|
Type byte
|
|
|
|
Delay bool
|
|
|
|
}
|
|
|
|
|
|
|
|
func (dif DeliveryInstructionsFlags) FlagByte() byte {
|
|
|
|
flag := byte(0x00)
|
|
|
|
if !dif.FirstFragment {
|
|
|
|
flag |= 0x01
|
|
|
|
}
|
|
|
|
flag |= dif.Type
|
|
|
|
if dif.Delay {
|
|
|
|
flag |= 0x10
|
|
|
|
}
|
|
|
|
return byte(flag)
|
|
|
|
}
|
|
|
|
|
2016-12-29 16:52:57 +00:00
|
|
|
func validFirstFragmentDeliveryInstructions(mapping common.Mapping) []byte {
|
2016-12-28 22:47:52 +00:00
|
|
|
data := []byte{}
|
|
|
|
|
|
|
|
flag := DeliveryInstructionsFlags{
|
|
|
|
FirstFragment: true,
|
|
|
|
Type: 0x02,
|
|
|
|
Delay: false,
|
2016-12-29 15:46:25 +00:00
|
|
|
}
|
|
|
|
data = append(data, flag.FlagByte())
|
2016-12-28 22:47:52 +00:00
|
|
|
|
|
|
|
tunnel_id := []byte{0x00, 0x00, 0x00, 0x01}
|
|
|
|
data = append(data, tunnel_id...)
|
|
|
|
|
2016-12-29 15:46:25 +00:00
|
|
|
hash := make([]byte, HASH_SIZE)
|
2016-12-28 22:47:52 +00:00
|
|
|
data = append(data, hash...)
|
|
|
|
|
2016-12-29 15:46:25 +00:00
|
|
|
if flag.Delay {
|
|
|
|
data = append(data, 1)
|
|
|
|
} else {
|
|
|
|
data = append(data, 0)
|
|
|
|
}
|
2016-12-28 22:47:52 +00:00
|
|
|
|
|
|
|
message_id := []byte{0x00, 0x00, 0x00, 0x02}
|
|
|
|
data = append(data, message_id...)
|
|
|
|
|
2016-12-29 16:52:57 +00:00
|
|
|
data = append(data, mapping...)
|
|
|
|
|
2016-12-28 22:47:52 +00:00
|
|
|
return data
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestReadDeliveryInstructions(t *testing.T) {
|
|
|
|
assert := assert.New(t)
|
|
|
|
|
2016-12-29 16:52:57 +00:00
|
|
|
mapping, _ := common.GoMapToMapping(map[string]string{})
|
|
|
|
_, _, err := readDeliveryInstructions(
|
|
|
|
validFirstFragmentDeliveryInstructions(
|
|
|
|
mapping,
|
|
|
|
),
|
|
|
|
)
|
2016-12-28 22:47:52 +00:00
|
|
|
assert.Nil(err)
|
|
|
|
}
|