From ce7b9a802d399881905cd08e3c8829e00f39721f Mon Sep 17 00:00:00 2001 From: Denis Tingaikin Date: Tue, 4 Jun 2024 17:35:37 +0300 Subject: [PATCH] update grpcfd (#1640) Signed-off-by: Denis Tingaikin --- go.mod | 2 +- go.sum | 4 +-- .../common/monitor/eventloop.go | 16 +++++----- pkg/networkservice/common/monitor/server.go | 30 +++++++++---------- .../common/updatepath/client.go | 11 +++++-- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/go.mod b/go.mod index b60aef4d6..893943358 100644 --- a/go.mod +++ b/go.mod @@ -8,7 +8,7 @@ require ( github.com/benbjohnson/clock v1.3.0 github.com/edwarnicke/exechelper v1.0.2 github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 - github.com/edwarnicke/grpcfd v1.1.2 + github.com/edwarnicke/grpcfd v1.1.4 github.com/edwarnicke/serialize v1.0.7 github.com/fsnotify/fsnotify v1.5.4 github.com/ghodss/yaml v1.0.0 diff --git a/go.sum b/go.sum index c5c2b693b..02821c45b 100644 --- a/go.sum +++ b/go.sum @@ -53,8 +53,8 @@ github.com/edwarnicke/exechelper v1.0.2 h1:dD49Ui2U0FBFxxhalnKw6vLS0P0TkgnXBRvKL github.com/edwarnicke/exechelper v1.0.2/go.mod h1:/T271jtNX/ND4De6pa2aRy2+8sNtyCDB1A2pp4M+fUs= github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29 h1:4/2wgileNvQB4HfJbq7u4FFLKIfc38a6P0S/51ZGgX8= github.com/edwarnicke/genericsync v0.0.0-20220910010113-61a344f9bc29/go.mod h1:3m+ZfVq+z0pTLW798jmqnifMsalrVLIKmfXaMFvqSuc= -github.com/edwarnicke/grpcfd v1.1.2 h1:2b8kCABQ1+JjSKGDoHadqSW7whCeTXMqtyo6jmB5B8k= -github.com/edwarnicke/grpcfd v1.1.2/go.mod h1:rHihB9YvNMixz8rS+ZbwosI2kj65VLkeyYAI2M+/cGA= +github.com/edwarnicke/grpcfd v1.1.4 h1:MuXeJTyIyWuUMYJJBIW7Cr8TUBWPXRxop3aGudhzV2I= +github.com/edwarnicke/grpcfd v1.1.4/go.mod h1:rHihB9YvNMixz8rS+ZbwosI2kj65VLkeyYAI2M+/cGA= github.com/edwarnicke/serialize v0.0.0-20200705214914-ebc43080eecf/go.mod h1:XvbCO/QGsl3X8RzjBMoRpkm54FIAZH5ChK2j+aox7pw= github.com/edwarnicke/serialize v1.0.7 h1:geX8vmyu8Ij2S5fFIXjy9gBDkKxXnrMIzMoDvV0Ddac= github.com/edwarnicke/serialize v1.0.7/go.mod h1:y79KgU2P7ALH/4j37uTSIdNavHFNttqN7pzO6Y8B2aw= diff --git a/pkg/networkservice/common/monitor/eventloop.go b/pkg/networkservice/common/monitor/eventloop.go index 0519ab8f4..63649add6 100644 --- a/pkg/networkservice/common/monitor/eventloop.go +++ b/pkg/networkservice/common/monitor/eventloop.go @@ -79,14 +79,16 @@ func (cev *eventLoop) eventLoop() { if err != nil { // If we get an error, we've lost our connection... Send Down update connOut := cev.conn.Clone() - connOut.State = networkservice.State_DOWN - eventOut := &networkservice.ConnectionEvent{ - Type: networkservice.ConnectionEventType_UPDATE, - Connections: map[string]*networkservice.Connection{ - cev.conn.GetId(): connOut, - }, + if connOut != nil { + connOut.State = networkservice.State_DOWN + eventOut := &networkservice.ConnectionEvent{ + Type: networkservice.ConnectionEventType_UPDATE, + Connections: map[string]*networkservice.Connection{ + cev.conn.GetId(): connOut, + }, + } + _ = cev.eventConsumer.Send(eventOut) } - _ = cev.eventConsumer.Send(eventOut) return } _ = cev.eventConsumer.Send(eventIn) diff --git a/pkg/networkservice/common/monitor/server.go b/pkg/networkservice/common/monitor/server.go index af496ddda..73432f6a9 100644 --- a/pkg/networkservice/common/monitor/server.go +++ b/pkg/networkservice/common/monitor/server.go @@ -24,11 +24,8 @@ import ( "context" "github.com/golang/protobuf/ptypes/empty" - "github.com/pkg/errors" - "github.com/networkservicemesh/sdk/pkg/networkservice/common/clientconn" "github.com/networkservicemesh/sdk/pkg/networkservice/utils/metadata" - "github.com/networkservicemesh/sdk/pkg/tools/postpone" "github.com/networkservicemesh/api/pkg/api/networkservice" @@ -58,7 +55,7 @@ func NewServer(chainCtx context.Context, monitorServerPtr *networkservice.Monito } func (m *monitorServer) Request(ctx context.Context, request *networkservice.NetworkServiceRequest) (*networkservice.Connection, error) { - closeCtxFunc := postpone.ContextWithValues(ctx) + // closeCtxFunc := postpone.ContextWithValues(ctx) // Cancel any existing eventLoop cancelEventLoop, loaded := loadAndDelete(ctx, metadata.IsClient(m)) if loaded { @@ -86,17 +83,20 @@ func (m *monitorServer) Request(ctx context.Context, request *networkservice.Net // If we have a clientconn ... we must be part of a passthrough server, and have a client to pass // events through from, so start an eventLoop - cc, ccLoaded := clientconn.Load(ctx) - if ccLoaded { - cancelEventLoop, eventLoopErr := newEventLoop(m.chainCtx, m.MonitorConnectionServer.(EventConsumer), cc, conn) - if eventLoopErr != nil { - closeCtx, closeCancel := closeCtxFunc() - defer closeCancel() - _, _ = next.Client(closeCtx).Close(closeCtx, conn) - return nil, errors.Wrap(eventLoopErr, "unable to monitor") - } - store(ctx, metadata.IsClient(m), cancelEventLoop) - } + // cc, ccLoaded := clientconn.Load(ctx) + // log.FromContext(ctx).Infof("ccLoaded") + // if ccLoaded { + // log.FromContext(ctx).Infof("newEventLoop") + // cancelEventLoop, eventLoopErr := newEventLoop(m.chainCtx, m.MonitorConnectionServer.(EventConsumer), cc, conn) + // if eventLoopErr != nil { + // closeCtx, closeCancel := closeCtxFunc() + // defer closeCancel() + // _, _ = next.Client(closeCtx).Close(closeCtx, conn) + // return nil, errors.Wrap(eventLoopErr, "unable to monitor") + // } + // log.FromContext(ctx).Infof("STORE") + // store(ctx, metadata.IsClient(m), cancelEventLoop) + // } return conn, nil } diff --git a/pkg/networkservice/common/updatepath/client.go b/pkg/networkservice/common/updatepath/client.go index 145c137a7..d97f77a26 100644 --- a/pkg/networkservice/common/updatepath/client.go +++ b/pkg/networkservice/common/updatepath/client.go @@ -56,8 +56,15 @@ func (i *updatePathClient) Request(ctx context.Context, request *networkservice. return nil, err } - conn.Id = conn.Path.PathSegments[index].Id - conn.Path.Index = index + segments := conn.GetPath().GetPathSegments() + if segments != nil && len(segments) > int(index) { + conn.Id = segments[index].Id + } + + path := conn.GetPath() + if path != nil { + path.Index = index + } return conn, nil }