generated from multiversx/mx-chain-ws-connector-template-go
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/feat/hyperblock' into feat/hyper…
…block
- Loading branch information
Showing
39 changed files
with
9,985 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,52 @@ | ||
[web_socket] | ||
[WebSocket] | ||
# IP with port used to recieve data via ws. Should be compatible with the one from node. See [HostDriverConfig].URL | ||
# from https://github.com/multiversx/mx-chain-go/blob/master/cmd/node/config/external.toml. | ||
url = "localhost:22111" | ||
URL = "localhost:22111" | ||
|
||
# Possible values: json, gogo protobuf. Should be compatible with [HostDriverConfig].MarshallerType | ||
marshaller_type = "gogo protobuf" | ||
MarshallerType = "gogo protobuf" | ||
|
||
# This flag describes the mode to start the WebSocket connector. Can be "client" or "server" | ||
mode = "server" | ||
Mode = "server" | ||
|
||
# Retry duration (receive/send data/acknowledge) in seconds | ||
retry_duration = 5 | ||
RetryDurationInSec = 5 | ||
|
||
# This flag specifies if we should send an acknowledge signal upon recieving data | ||
with_acknowledge = true | ||
WithAcknowledge = true | ||
|
||
# The duration in seconds to wait for an acknowledgement message | ||
acknowledge_timeout_in_sec = 5 | ||
AcknowledgeTimeoutInSec = 5 | ||
|
||
# Signals if in case of data payload processing error, we should send the ack signal or not. If you want to block | ||
# incoming data in case of a local error, this should be set to true. | ||
blocking_ack_on_error = true | ||
BlockingAckOnError = true | ||
|
||
# This flag specifies if we should drop messages if there is no connection to the host | ||
drop_messages_if_no_connection = false | ||
version = 1 | ||
DropMessagesIfNoConnection = false | ||
|
||
# Version specifies payload version (default = 1) | ||
Version = 1 | ||
|
||
[DataPool] | ||
NumberOfShards = 3 | ||
|
||
# Should be smaller then PruningWindow | ||
MaxDelta = 10 | ||
PruningWindow = 1000 | ||
|
||
# Defines the number of active persisters to keep open | ||
NumPersistersToKeep = 2 | ||
|
||
[OutportBlocksStorage] | ||
[OutportBlocksStorage.Cache] | ||
Name = "OutportBlocksStorage" | ||
Capacity = 100 | ||
Type = "SizeLRU" | ||
SizeInBytes = 209715200 # 200MB | ||
[OutportBlocksStorage.DB] | ||
FilePath = "OutportBlocks" | ||
Type = "LvlDBSerial" | ||
BatchDelaySeconds = 2 | ||
MaxBatchSize = 100 | ||
MaxOpenFiles = 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package connector | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
logger "github.com/multiversx/mx-chain-logger-go" | ||
"github.com/multiversx/mx-chain-ws-connector-template-go/config" | ||
"github.com/multiversx/mx-chain-ws-connector-template-go/factory" | ||
) | ||
|
||
var log = logger.GetOrCreate("connectorRunner") | ||
|
||
// ErrNilConfig signals that a nil config structure was provided | ||
var ErrNilConfig = errors.New("nil configs provided") | ||
|
||
type connectorRunner struct { | ||
config *config.Config | ||
importDBMode bool | ||
} | ||
|
||
// NewConnectorRunner will create a new connector runner instance | ||
func NewConnectorRunner(cfg *config.Config, importDBMode bool) (*connectorRunner, error) { | ||
if cfg == nil { | ||
return nil, ErrNilConfig | ||
} | ||
|
||
return &connectorRunner{ | ||
config: cfg, | ||
importDBMode: importDBMode, | ||
}, nil | ||
} | ||
|
||
// Start will trigger connector service | ||
func (cr *connectorRunner) Start() error { | ||
storer, err := factory.CreateStorer(*cr.config, cr.importDBMode) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
dataProcessor, err := factory.CreateDataProcessor(*cr.config, storer) | ||
if err != nil { | ||
return fmt.Errorf("cannot create ws firehose data processor, error: %w", err) | ||
} | ||
|
||
wsClient, err := factory.CreateWSConnector(cr.config.WebSocket, dataProcessor) | ||
if err != nil { | ||
return fmt.Errorf("cannot create ws firehose connector, error: %w", err) | ||
} | ||
|
||
interrupt := make(chan os.Signal, 1) | ||
signal.Notify(interrupt, syscall.SIGINT, syscall.SIGTERM) | ||
|
||
log.Info("starting ws client...") | ||
|
||
<-interrupt | ||
|
||
log.Info("application closing, calling Close on all subcomponents...") | ||
|
||
err = storer.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = wsClient.Close() | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return err | ||
} |
Oops, something went wrong.