Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
miiu96 committed May 12, 2023
1 parent 4d5cc99 commit ae1775f
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 11 deletions.
9 changes: 6 additions & 3 deletions cmd/node/config/external.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion config/externalConfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
3 changes: 2 additions & 1 deletion outport/factory/hostDriverFactory.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down
29 changes: 29 additions & 0 deletions outport/factory/hostDriverFactory_test.go
Original file line number Diff line number Diff line change
@@ -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))
}
6 changes: 3 additions & 3 deletions outport/host/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit ae1775f

Please sign in to comment.