ttrpc: use odd numbers for client initiated streams

Following the convention of http2, we now use odd stream ids for client
initiated streams. This makes it easier to tell who initiates the
stream. We enforce the convention on the server-side.

This allows us to upgrade the protocol in the future to have server
initiated streams.

Signed-off-by: Stephen J Day <stephen.day@docker.com>
This commit is contained in:
Stephen J Day
2017-11-27 18:05:12 -08:00
parent 07cd4de2f2
commit bdb2ab7a81
2 changed files with 22 additions and 1 deletions

View File

@@ -27,6 +27,7 @@ type Client struct {
func NewClient(conn net.Conn) *Client {
c := &Client{
codec: codec{},
requestID: 1,
channel: newChannel(conn, conn),
sendRequests: make(chan sendRequest),
recvRequests: make(chan recvRequest),
@@ -44,7 +45,7 @@ func (c *Client) Call(ctx context.Context, service, method string, req, resp int
return err
}
requestID := atomic.AddUint32(&c.requestID, 1)
requestID := atomic.AddUint32(&c.requestID, 2)
request := Request{
Service: service,
Method: method,