Skip to content

Commit

Permalink
fix end-packet #1.
Browse files Browse the repository at this point in the history
* End-packet payload shall be ZERO-length byte-string.
* 0xff shall be matching 0x9f.
  • Loading branch information
prataprc committed Jun 29, 2017
1 parent f4e4c06 commit a04c1b9
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
19 changes: 16 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,16 @@ the following format:
**end-packet**

```text
| len | tag1 | 0xff |
| len | tag1 | 0x40 | 0xff |
```

* If packet denotes a stream-end, payload will be 1-byte 0xff,
and not encoded as byte-array.
* End-packet does not carry any useful payload, it simply signifies a stream
close.
* For that, tag1 opaque-value is required to identify the stream.
* 0x40 is the single-byte payload for this packet, which says that the
payload-data is ZERO bytes.
* The last 0xff is important since it will match with 0x9f that indicates
a stream-start as Indefinite array of items.

**Reading a frame from socket**

Expand All @@ -148,6 +153,14 @@ That is a total of: 1 + 3 + 1 + 4
Incidentally these 9 bytes are enough to learn how many more bytes to read
from the socket to complete the entire packet.

**Regarding Opaque-value**

By design opaque value should be >= 256. These are ephimeral tag values
that do not carry any meaning other than identifying the stream. Opaque
values will continuously reused for the life-time of connection. Users
are expected to give a range of these ephemeral tag-values, and gofast
will skip [reserved TAGS](https://www.iana.org/assignments/cbor-tags/cbor-tags.xhtml).

Reserved-tags
-------------

Expand Down
5 changes: 4 additions & 1 deletion go_rx.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ func (t *Transport) unframepkt(

ln, m := cborItemLength(pad[n:])
n += m
if finish { // railing 0xff
ln++
}

// read the full packet
n = copy(packet, pad[n:])
Expand All @@ -98,7 +101,7 @@ func (t *Transport) unframepkt(
rxpkt.opaque, payload = readtp(packet[:ln])
rxpkt.post, rxpkt.request = post, request
rxpkt.start, rxpkt.strmsg, rxpkt.finish = start, stream, finish
if rxpkt.finish /*rxpkt.payload[0] == 0xff*/ { // end-of-stream
if rxpkt.finish { // end-of-stream
return
}
// tags
Expand Down
1 change: 1 addition & 0 deletions go_tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func (t *Transport) doTx() {
// consolidate.
for _, arg := range batch {
if len(arg.packet) > 0 {
//fmt.Println(hexstring(arg.packet))
n += copy(tcpwrite_buf[n:], arg.packet)
atomic.AddUint64(&t.n_tx, 1)
}
Expand Down
6 changes: 4 additions & 2 deletions tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ func (t *Transport) finish(stream *Stream, out []byte) (n int) {
atomic.AddUint64(&t.n_txfin, 1)
var scratch [16]byte
n = tag2cbor(tagCborPrefix, out) // prefix
out[n] = 0xc8 // 0xc7 (end stream, 0b110_01000 <tag,8>)
out[n] = 0xc8 // 0xc8 (end stream, 0b110_01000 <tag,8>)
n += 1 //
m := tag2cbor(stream.opaque, scratch[:]) // tag-opaque
scratch[m] = 0xff // 0xff (payload)
scratch[m] = 0x40 // zero-len byte-string
m += 1
n += valbytes2cbor(scratch[:m], out[n:]) // packet
out[n] = 0xff // 0xff CBOR indefinite end.
n += 1
return n
}

Expand Down
2 changes: 1 addition & 1 deletion tx_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func TestFinish(t *testing.T) {
transc := newClient("client", addr, "").Handshake() // init client
transv := <-serverch

ref := []byte{217, 217, 247, 200, 68, 217, 1, 12, 255}
ref := []byte{217, 217, 247, 200, 68, 217, 1, 12, 64, 255}
stream := transc.getlocalstream(false, nil)
out := make([]byte, 1024)
n := transc.finish(stream, out)
Expand Down

0 comments on commit a04c1b9

Please sign in to comment.