From ae1775f4ac30a24c290ab3685c61bb472ba122cb Mon Sep 17 00:00:00 2001 From: Iuga Mihai Date: Fri, 12 May 2023 13:00:35 +0300 Subject: [PATCH] fixes --- cmd/node/config/external.toml | 9 ++++--- config/externalConfig.go | 2 +- go.mod | 2 +- go.sum | 4 ++-- outport/factory/hostDriverFactory.go | 3 ++- outport/factory/hostDriverFactory_test.go | 29 +++++++++++++++++++++++ outport/host/driver.go | 6 ++--- 7 files changed, 44 insertions(+), 11 deletions(-) diff --git a/cmd/node/config/external.toml b/cmd/node/config/external.toml index 7de429cf6cc..03a13a61ed0 100644 --- a/cmd/node/config/external.toml +++ b/cmd/node/config/external.toml @@ -44,13 +44,16 @@ [HostDriverConfig] # This flag shall only be used for observer nodes Enabled = false - # This flag will start the WebSocket connector as server or client - IsServer = false - # The url of the WebSocket client/server + # This flag will start the WebSocket connector as server or client( can be "client" or "server") + Mode = "client" + # URL for the WebSocket client/server connection + # This value represents the IP address and port number that the WebSocket client or server will use to establish a connection. URL = "127.0.0.1:22111" + # After a message will be sent it will wait for an ack message if this flag is enabled WithAcknowledge = true # Currently, only "json" is supported. In the future, "gogo protobuf" could also be supported MarshallerType = "json" # The number of seconds when the client will try again to send the data RetryDurationInSec = 5 + # Signals if in case of data payload processing error, we should send the ack signal or not BlockingAckOnError = false diff --git a/config/externalConfig.go b/config/externalConfig.go index fba21834846..f5609ed3a6c 100644 --- a/config/externalConfig.go +++ b/config/externalConfig.go @@ -41,10 +41,10 @@ type CovalentConfig struct { // HostDriverConfig will hold the configuration for WebSocket driver type HostDriverConfig struct { Enabled bool - IsServer bool WithAcknowledge bool BlockingAckOnError bool URL string MarshallerType string + Mode string RetryDurationInSec int } diff --git a/go.mod b/go.mod index 64728f6e5e8..642937773a7 100644 --- a/go.mod +++ b/go.mod @@ -13,7 +13,7 @@ require ( github.com/google/gops v0.3.18 github.com/gorilla/websocket v1.5.0 github.com/mitchellh/mapstructure v1.5.0 - github.com/multiversx/mx-chain-communication-go v0.0.0-20230511105730-3400290e42c0 + github.com/multiversx/mx-chain-communication-go v0.0.0-20230512095548-5bc637293104 github.com/multiversx/mx-chain-core-go v1.2.1-0.20230510143029-ab37792342df github.com/multiversx/mx-chain-crypto-go v1.2.5 github.com/multiversx/mx-chain-es-indexer-go v1.4.1-0.20230331083741-0fd8a2156e96 diff --git a/go.sum b/go.sum index c48acfd3bda..b3eca275b43 100644 --- a/go.sum +++ b/go.sum @@ -609,8 +609,8 @@ github.com/multiformats/go-varint v0.0.6 h1:gk85QWKxh3TazbLxED/NlDVv8+q+ReFJk7Y2 github.com/multiformats/go-varint v0.0.6/go.mod h1:3Ls8CIEsrijN6+B7PbrXRPxHRPuXSrVKRY101jdMZYE= github.com/multiversx/concurrent-map v0.1.4 h1:hdnbM8VE4b0KYJaGY5yJS2aNIW9TFFsUYwbO0993uPI= github.com/multiversx/concurrent-map v0.1.4/go.mod h1:8cWFRJDOrWHOTNSqgYCUvwT7c7eFQ4U2vKMOp4A/9+o= -github.com/multiversx/mx-chain-communication-go v0.0.0-20230511105730-3400290e42c0 h1:dZa9ZfN9R605VZYJNhC36eSXJumADO6bHNZMhMdMLfg= -github.com/multiversx/mx-chain-communication-go v0.0.0-20230511105730-3400290e42c0/go.mod h1:GPHOm4HSXbvC0IotMziWXQmhtsUe69ScBPYsb+mF9bk= +github.com/multiversx/mx-chain-communication-go v0.0.0-20230512095548-5bc637293104 h1:oFsYNkebv7TQygdEjN4aGgQ8ICLPmS9bDJmzlOHtU2Y= +github.com/multiversx/mx-chain-communication-go v0.0.0-20230512095548-5bc637293104/go.mod h1:GPHOm4HSXbvC0IotMziWXQmhtsUe69ScBPYsb+mF9bk= github.com/multiversx/mx-chain-core-go v1.1.30/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk= github.com/multiversx/mx-chain-core-go v1.1.31/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk= github.com/multiversx/mx-chain-core-go v1.1.34/go.mod h1:8gGEQv6BWuuJwhd25qqhCOZbBSv9mk+hLeKvinSaSMk= diff --git a/outport/factory/hostDriverFactory.go b/outport/factory/hostDriverFactory.go index a9cfce25eda..78dbac7db18 100644 --- a/outport/factory/hostDriverFactory.go +++ b/outport/factory/hostDriverFactory.go @@ -17,12 +17,13 @@ type ArgsHostDriverFactory struct { var log = logger.GetOrCreate("outport/factory/hostdriver") +// CreateHostDriver will create a new instance of outport.Driver func CreateHostDriver(args ArgsHostDriverFactory) (outport.Driver, error) { wsHost, err := factory.CreateWebSocketHost(factory.ArgsWebSocketHost{ WebSocketConfig: data.WebSocketConfig{ URL: args.HostConfig.URL, WithAcknowledge: args.HostConfig.WithAcknowledge, - IsServer: args.HostConfig.IsServer, + Mode: args.HostConfig.Mode, RetryDurationInSec: args.HostConfig.RetryDurationInSec, BlockingAckOnError: args.HostConfig.BlockingAckOnError, }, diff --git a/outport/factory/hostDriverFactory_test.go b/outport/factory/hostDriverFactory_test.go index 7312cd2e2d8..834fa793b6c 100644 --- a/outport/factory/hostDriverFactory_test.go +++ b/outport/factory/hostDriverFactory_test.go @@ -1 +1,30 @@ package factory + +import ( + "fmt" + "testing" + + "github.com/multiversx/mx-chain-communication-go/websocket/data" + "github.com/multiversx/mx-chain-go/config" + "github.com/multiversx/mx-chain-go/testscommon" + "github.com/stretchr/testify/require" +) + +func TestCreateHostDriver(t *testing.T) { + t.Parallel() + + args := ArgsHostDriverFactory{ + HostConfig: config.HostDriverConfig{ + URL: "localhost", + RetryDurationInSec: 1, + MarshallerType: "json", + Mode: data.ModeClient, + }, + Marshaller: &testscommon.MarshalizerMock{}, + } + + driver, err := CreateHostDriver(args) + require.Nil(t, err) + require.NotNil(t, driver) + require.Equal(t, "*host.hostDriver", fmt.Sprintf("%T", driver)) +} diff --git a/outport/host/driver.go b/outport/host/driver.go index 2b12afd2612..017cdfecefb 100644 --- a/outport/host/driver.go +++ b/outport/host/driver.go @@ -24,6 +24,7 @@ type hostDriver struct { log core.Logger } +// NewHostDriver will create a new instance of hostDriver func NewHostDriver(args ArgsHostDriver) (*hostDriver, error) { if check.IfNil(args.SenderHost) { return nil, ErrNilHost @@ -43,6 +44,7 @@ func NewHostDriver(args ArgsHostDriver) (*hostDriver, error) { }, nil } +// SaveBlock will handle the saving of block func (o *hostDriver) SaveBlock(outportBlock *outport.OutportBlock) error { return o.handleAction(outportBlock, outport.TopicSaveBlock) } @@ -89,14 +91,12 @@ func (o *hostDriver) handleAction(args interface{}, topic string) error { marshalledPayload, err := o.marshaller.Marshal(args) if err != nil { - o.log.Error("cannot marshal block", "topic", topic, "error", err) return fmt.Errorf("%w while marshaling block for topic %s", err, topic) } err = o.senderHost.Send(marshalledPayload, topic) if err != nil { - o.log.Error("cannot send on route", "topic", topic, "error", err) - return fmt.Errorf("%w while sending data on route for topic %s", err, topic) + return fmt.Errorf("%w while sendcing data on route for topic %s", err, topic) } return nil