Files
Go_I2p/lib/tunnel/delivery_test.go
idk 0ec4f55fa9 Check in unchecked-in common library fixes, start implementing transports.
Since I turned out to be implementing parts of Noise which I did not need to implement, I'm taking a different approach, and doing an unmodified Noise transport first and then making our modifications to it. That should reduce what I need to do to message pre-processing mostly, I think.
2022-07-11 23:41:58 -04:00

69 lines
1.3 KiB
Go

package tunnel
import (
"testing"
common "github.com/go-i2p/go-i2p/lib/common/data"
"github.com/stretchr/testify/assert"
)
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)
}
func validFirstFragmentDeliveryInstructions(mapping common.Mapping) []byte {
data := []byte{}
flag := DeliveryInstructionsFlags{
FirstFragment: true,
Type: 0x02,
Delay: false,
}
data = append(data, flag.FlagByte())
tunnel_id := []byte{0x00, 0x00, 0x00, 0x01}
data = append(data, tunnel_id...)
hash := make([]byte, HASH_SIZE)
data = append(data, hash...)
if flag.Delay {
data = append(data, 1)
} else {
data = append(data, 0)
}
message_id := []byte{0x00, 0x00, 0x00, 0x02}
data = append(data, message_id...)
data = append(data, mapping.Data()...)
return data
}
func TestReadDeliveryInstructions(t *testing.T) {
assert := assert.New(t)
mapping, _ := common.GoMapToMapping(map[string]string{})
_, _, err := readDeliveryInstructions(
validFirstFragmentDeliveryInstructions(
*mapping,
),
)
assert.Nil(err)
}