diff options
author | Matus Mrekaj <matus.mrekaj@pantheon.tech> | 2019-10-22 15:05:39 +0200 |
---|---|---|
committer | Matus Mrekaj <matus.mrekaj@pantheon.tech> | 2019-10-30 14:42:35 +0100 |
commit | 58601b470bbd4e5ef534fed83511aa5a7f1c2d1e (patch) | |
tree | 1c0c1176567d66e1b7be45c51f445dd5baa28dee /proxy/client.go | |
parent | cc80dbcaaaca8bf1b6042fead850d456cf589a4e (diff) |
fix data races in proxy server
Signed-off-by: Matus Mrekaj <matus.mrekaj@pantheon.tech>
Change-Id: I932d560548ee816e28683243a7318a2a7fbbb24a
Diffstat (limited to 'proxy/client.go')
-rw-r--r-- | proxy/client.go | 73 |
1 files changed, 47 insertions, 26 deletions
diff --git a/proxy/client.go b/proxy/client.go index 4f2df0f..7f92946 100644 --- a/proxy/client.go +++ b/proxy/client.go @@ -1,8 +1,22 @@ +// Copyright (c) 2019 Cisco and/or its affiliates. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at: +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + package proxy import ( "fmt" - "log" + "git.fd.io/govpp.git/core" "net/rpc" "reflect" "time" @@ -40,7 +54,8 @@ func (c *Client) NewStatsClient() (*StatsClient, error) { // NewBinapiClient returns new BinapiClient which implements api.Channel. func (c *Client) NewBinapiClient() (*BinapiClient, error) { binapi := &BinapiClient{ - rpc: c.rpc, + rpc: c.rpc, + timeout: core.DefaultReplyTimeout, } return binapi, nil } @@ -103,27 +118,31 @@ func (s *StatsClient) GetBufferStats(bufStats *api.BufferStats) error { } type BinapiClient struct { - rpc *rpc.Client + rpc *rpc.Client + timeout time.Duration } func (b *BinapiClient) SendRequest(msg api.Message) api.RequestCtx { req := &requestCtx{ - rpc: b.rpc, - req: msg, + rpc: b.rpc, + timeout: b.timeout, + req: msg, } - log.Printf("SendRequest: %T %+v", msg, msg) + log.Debugf("SendRequest: %T %+v", msg, msg) return req } type requestCtx struct { - rpc *rpc.Client - req api.Message + rpc *rpc.Client + req api.Message + timeout time.Duration } func (r *requestCtx) ReceiveReply(msg api.Message) error { req := BinapiRequest{ Msg: r.req, ReplyMsg: msg, + Timeout: r.timeout, } resp := BinapiResponse{} @@ -140,16 +159,18 @@ func (r *requestCtx) ReceiveReply(msg api.Message) error { func (b *BinapiClient) SendMultiRequest(msg api.Message) api.MultiRequestCtx { req := &multiRequestCtx{ - rpc: b.rpc, - req: msg, + rpc: b.rpc, + timeout: b.timeout, + req: msg, } - log.Printf("SendMultiRequest: %T %+v", msg, msg) + log.Debugf("SendMultiRequest: %T %+v", msg, msg) return req } type multiRequestCtx struct { - rpc *rpc.Client - req api.Message + rpc *rpc.Client + req api.Message + timeout time.Duration index int replies []api.Message @@ -162,6 +183,7 @@ func (r *multiRequestCtx) ReceiveReply(msg api.Message) (stop bool, err error) { Msg: r.req, ReplyMsg: msg, IsMulti: true, + Timeout: r.timeout, } resp := BinapiResponse{} @@ -189,24 +211,23 @@ func (b *BinapiClient) SubscribeNotification(notifChan chan api.Message, event a } func (b *BinapiClient) SetReplyTimeout(timeout time.Duration) { - req := BinapiTimeoutRequest{Timeout: timeout} - resp := BinapiTimeoutResponse{} - if err := b.rpc.Call("BinapiRPC.SetTimeout", req, &resp); err != nil { - log.Println(err) - } + b.timeout = timeout } func (b *BinapiClient) CheckCompatiblity(msgs ...api.Message) error { + msgNamesCrscs := make([]string, 0, len(msgs)) + for _, msg := range msgs { - req := BinapiCompatibilityRequest{ - MsgName: msg.GetMessageName(), - Crc: msg.GetCrcString(), - } - resp := BinapiCompatibilityResponse{} - if err := b.rpc.Call("BinapiRPC.Compatibility", req, &resp); err != nil { - return err - } + msgNamesCrscs = append(msgNamesCrscs, msg.GetMessageName()+"_"+msg.GetCrcString()) } + + req := BinapiCompatibilityRequest{MsgNameCrcs: msgNamesCrscs} + resp := BinapiCompatibilityResponse{} + + if err := b.rpc.Call("BinapiRPC.Compatibility", req, &resp); err != nil { + return err + } + return nil } |