From 136c8222c493a9a5a44a89db153571f7ae5d75a5 Mon Sep 17 00:00:00 2001 From: Sergey Elantsev Date: Mon, 9 Mar 2020 15:19:17 +0300 Subject: fixed style: unnecessary type cast after type switch and some minor issues. --- internal/pkg/table/adj.go | 2 +- pkg/server/bmp.go | 6 ++---- pkg/server/fsm.go | 14 ++++++-------- pkg/server/rpki.go | 6 +++--- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/internal/pkg/table/adj.go b/internal/pkg/table/adj.go index aedc41d6..49315e87 100644 --- a/internal/pkg/table/adj.go +++ b/internal/pkg/table/adj.go @@ -228,7 +228,7 @@ func (adj *AdjRib) MarkLLGRStaleOrDrop(rfList []bgp.RouteFamily) []*Path { func (adj *AdjRib) Select(family bgp.RouteFamily, accepted bool, option ...TableSelectOption) (*Table, error) { t, ok := adj.table[family] if !ok { - t = NewTable((family)) + t = NewTable(family) } option = append(option, TableSelectOption{adj: true}) return t.Select(option...) diff --git a/pkg/server/bmp.go b/pkg/server/bmp.go index f96143c7..22be03ae 100644 --- a/pkg/server/bmp.go +++ b/pkg/server/bmp.go @@ -192,10 +192,8 @@ func (b *bmpClient) loop() { } } } - } else { - if err := write(bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, msg.PostPolicy, 0, msg.FourBytesAs, info, msg.Timestamp.Unix(), msg.Payload)); err != nil { - return false - } + } else if err := write(bmpPeerRoute(bmp.BMP_PEER_TYPE_GLOBAL, msg.PostPolicy, 0, msg.FourBytesAs, info, msg.Timestamp.Unix(), msg.Payload)); err != nil { + return false } case *watchEventBestPath: info := &table.PeerInfo{ diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go index 35172bd2..b5bcd2d8 100644 --- a/pkg/server/fsm.go +++ b/pkg/server/fsm.go @@ -1254,9 +1254,8 @@ func (h *fsmHandler) opensent(ctx context.Context) (bgp.FSMState, *fsmStateReaso continue } e := i.(*fsmMsg) - switch e.MsgData.(type) { + switch m := e.MsgData.(type) { case *bgp.BGPMessage: - m := e.MsgData.(*bgp.BGPMessage) if m.Header.Type == bgp.BGP_MSG_OPEN { fsm.lock.Lock() fsm.recvOpen = m @@ -1408,8 +1407,8 @@ func (h *fsmHandler) opensent(ctx context.Context) (bgp.FSMState, *fsmStateReaso return bgp.BGP_FSM_IDLE, newfsmStateReason(fsmInvalidMsg, nil, nil) } case *bgp.MessageError: - m, _ := fsm.sendNotificationFromErrorMsg(e.MsgData.(*bgp.MessageError)) - return bgp.BGP_FSM_IDLE, newfsmStateReason(fsmInvalidMsg, m, nil) + msg, _ := fsm.sendNotificationFromErrorMsg(m) + return bgp.BGP_FSM_IDLE, newfsmStateReason(fsmInvalidMsg, msg, nil) default: log.WithFields(log.Fields{ "Topic": "Peer", @@ -1524,9 +1523,8 @@ func (h *fsmHandler) openconfirm(ctx context.Context) (bgp.FSMState, *fsmStateRe continue } e := i.(*fsmMsg) - switch e.MsgData.(type) { + switch m := e.MsgData.(type) { case *bgp.BGPMessage: - m := e.MsgData.(*bgp.BGPMessage) if m.Header.Type == bgp.BGP_MSG_KEEPALIVE { return bgp.BGP_FSM_ESTABLISHED, newfsmStateReason(fsmOpenMsgNegotiated, nil, nil) } @@ -1534,8 +1532,8 @@ func (h *fsmHandler) openconfirm(ctx context.Context) (bgp.FSMState, *fsmStateRe h.conn.Close() return bgp.BGP_FSM_IDLE, newfsmStateReason(fsmInvalidMsg, nil, nil) case *bgp.MessageError: - m, _ := fsm.sendNotificationFromErrorMsg(e.MsgData.(*bgp.MessageError)) - return bgp.BGP_FSM_IDLE, newfsmStateReason(fsmInvalidMsg, m, nil) + msg, _ := fsm.sendNotificationFromErrorMsg(m) + return bgp.BGP_FSM_IDLE, newfsmStateReason(fsmInvalidMsg, msg, nil) default: log.WithFields(log.Fields{ "Topic": "Peer", diff --git a/pkg/server/rpki.go b/pkg/server/rpki.go index 9eb3d2b7..00fbfcfa 100644 --- a/pkg/server/rpki.go +++ b/pkg/server/rpki.go @@ -64,10 +64,10 @@ type roaManager struct { func newROAManager(table *table.ROATable) *roaManager { m := &roaManager{ - table: table, + eventCh: make(chan *roaEvent), + clientMap: make(map[string]*roaClient), + table: table, } - m.eventCh = make(chan *roaEvent) - m.clientMap = make(map[string]*roaClient) return m } -- cgit v1.2.3