mirror of
https://github.com/go-i2p/go-i2p.git
synced 2025-07-04 05:26:51 -04:00
follow on fragment flag parsing
This commit is contained in:
@ -178,13 +178,51 @@ func (delivery_instructions DeliveryInstructions) Type() (int, error) {
|
|||||||
// Read the integer stored in the 6-1 bits of a FOLLOW_ON_FRAGMENT's flag, indicating
|
// Read the integer stored in the 6-1 bits of a FOLLOW_ON_FRAGMENT's flag, indicating
|
||||||
// the fragment number.
|
// the fragment number.
|
||||||
func (delivery_instructions DeliveryInstructions) FragmentNumber() (int, error) {
|
func (delivery_instructions DeliveryInstructions) FragmentNumber() (int, error) {
|
||||||
return 0, nil
|
di_type, err := delivery_instructions.Type()
|
||||||
|
if err != nil {
|
||||||
|
return 0, err
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Read the 6-1 bits of the Delivery Instructions
|
||||||
|
to determine the FragmentNumber of Follow On Fragments
|
||||||
|
|
||||||
|
xnnnnnnx
|
||||||
|
&01111110 bit shift
|
||||||
|
---------
|
||||||
|
0??????0 >> 1 => Integer(??????)
|
||||||
|
*/
|
||||||
|
if di_type == FOLLOW_ON_FRAGMENT {
|
||||||
|
return common.Integer(
|
||||||
|
[]byte{((delivery_instructions[0] & 0x7e) >> 1)},
|
||||||
|
), nil
|
||||||
|
}
|
||||||
|
return 0, errors.New("Fragment Number only exists on FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Read the value of the 0 bit of a FOLLOW_ON_FRAGMENT, which is set to 1 to indicate the
|
// Read the value of the 0 bit of a FOLLOW_ON_FRAGMENT, which is set to 1 to indicate the
|
||||||
// last fragment.
|
// last fragment.
|
||||||
func (delivery_instructions DeliveryInstructions) LastFollowOnFragment() (bool, error) {
|
func (delivery_instructions DeliveryInstructions) LastFollowOnFragment() (bool, error) {
|
||||||
|
di_type, err := delivery_instructions.Type()
|
||||||
|
if err != nil {
|
||||||
|
return false, err
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
Check the 0 bit of the Delivery Instructions
|
||||||
|
to determine if this is the last Follow On Fragment
|
||||||
|
|
||||||
|
xxxxxxxx
|
||||||
|
&00000001
|
||||||
|
---------
|
||||||
|
0000000? => n
|
||||||
|
*/
|
||||||
|
if di_type == FOLLOW_ON_FRAGMENT {
|
||||||
|
if delivery_instructions[0]&0x01 == 0x01 {
|
||||||
return true, nil
|
return true, nil
|
||||||
|
} else {
|
||||||
|
return false, nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false, errors.New("Last Fragment only exists for FOLLOW_ON_FRAGMENT Delivery Instructions")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return the delivery type for these DeliveryInstructions, can be of type
|
// Return the delivery type for these DeliveryInstructions, can be of type
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package tunnel
|
package tunnel
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/hkparker/go-i2p/lib/common"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
@ -23,7 +24,7 @@ func (dif DeliveryInstructionsFlags) FlagByte() byte {
|
|||||||
return byte(flag)
|
return byte(flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
func validFirstFragmentDeliveryInstructions() []byte {
|
func validFirstFragmentDeliveryInstructions(mapping common.Mapping) []byte {
|
||||||
data := []byte{}
|
data := []byte{}
|
||||||
|
|
||||||
flag := DeliveryInstructionsFlags{
|
flag := DeliveryInstructionsFlags{
|
||||||
@ -48,12 +49,19 @@ func validFirstFragmentDeliveryInstructions() []byte {
|
|||||||
message_id := []byte{0x00, 0x00, 0x00, 0x02}
|
message_id := []byte{0x00, 0x00, 0x00, 0x02}
|
||||||
data = append(data, message_id...)
|
data = append(data, message_id...)
|
||||||
|
|
||||||
|
data = append(data, mapping...)
|
||||||
|
|
||||||
return data
|
return data
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestReadDeliveryInstructions(t *testing.T) {
|
func TestReadDeliveryInstructions(t *testing.T) {
|
||||||
assert := assert.New(t)
|
assert := assert.New(t)
|
||||||
|
|
||||||
_, _, err := readDeliveryInstructions(validFirstFragmentDeliveryInstructions())
|
mapping, _ := common.GoMapToMapping(map[string]string{})
|
||||||
|
_, _, err := readDeliveryInstructions(
|
||||||
|
validFirstFragmentDeliveryInstructions(
|
||||||
|
mapping,
|
||||||
|
),
|
||||||
|
)
|
||||||
assert.Nil(err)
|
assert.Nil(err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user