-
Notifications
You must be signed in to change notification settings - Fork 197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
En 6847 timestamp in p2p message #2023
Changes from 6 commits
9a4bbd4
c3e3570
192e218
f333910
869a7dd
0d42edb
260a837
314a86b
f804325
5d3b293
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# The main marshalizer, used in internodes communication | ||
# Type identifies the marshalizer | ||
# SizeCheckDelta the maximum allow drift between the input data buffer and | ||
# the reencoded version (in percents). | ||
# 0 disables the feature. | ||
[Marshalizer] | ||
Type = "gogo protobuf" | ||
SizeCheckDelta = 10 | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
package main | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
"os" | ||
"os/signal" | ||
|
@@ -16,12 +17,15 @@ import ( | |
"github.com/ElrondNetwork/elrond-go/config" | ||
"github.com/ElrondNetwork/elrond-go/core" | ||
"github.com/ElrondNetwork/elrond-go/display" | ||
"github.com/ElrondNetwork/elrond-go/marshal" | ||
factoryMarshalizer "github.com/ElrondNetwork/elrond-go/marshal/factory" | ||
"github.com/ElrondNetwork/elrond-go/p2p" | ||
"github.com/ElrondNetwork/elrond-go/p2p/libp2p" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
const defaultLogsPath = "logs" | ||
const filePathPlaceholder = "[path]" | ||
|
||
var ( | ||
seedNodeHelpTemplate = `NAME: | ||
|
@@ -66,8 +70,17 @@ VERSION: | |
Name: "log-save", | ||
Usage: "Boolean option for enabling log saving. If set, it will automatically save all the logs into a file.", | ||
} | ||
|
||
// configurationFile defines a flag for the path to the main toml configuration file | ||
configurationFile = cli.StringFlag{ | ||
Name: "config", | ||
Usage: "The `" + filePathPlaceholder + "` for the main configuration file. This TOML file contain the main " + | ||
"configurations such as the marshalizer type", | ||
Value: "./config/config.toml", | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We didn't have an option for a custom configuration file before this? |
||
p2pConfigurationFile = "./config/p2p.toml" | ||
|
||
// ErrMarshalizerCreation signals that the marshalizer cannot be created based on provided data | ||
ErrMarshalizerCreation = errors.New("error creating marshalizer") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need for this define - just create the error where it is needed. it is in main There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
) | ||
|
||
var log = logger.GetOrCreate("main") | ||
|
@@ -77,7 +90,13 @@ func main() { | |
cli.AppHelpTemplate = seedNodeHelpTemplate | ||
app.Name = "SeedNode CLI App" | ||
app.Usage = "This is the entry point for starting a new seed node - the app will help bootnodes connect to the network" | ||
app.Flags = []cli.Flag{port, p2pSeed, logLevel, logSaveFile} | ||
app.Flags = []cli.Flag{ | ||
port, | ||
p2pSeed, | ||
logLevel, | ||
logSaveFile, | ||
configurationFile, | ||
} | ||
app.Version = "v0.0.1" | ||
app.Authors = []cli.Author{ | ||
{ | ||
|
@@ -99,6 +118,18 @@ func main() { | |
|
||
func startNode(ctx *cli.Context) error { | ||
var err error | ||
|
||
configurationFileName := ctx.GlobalString(configurationFile.Name) | ||
generalConfig, err := loadMainConfig(configurationFileName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
internalMarshalizer, err := factoryMarshalizer.NewMarshalizer(generalConfig.Marshalizer.Type) | ||
if err != nil { | ||
return fmt.Errorf("%w (internal): %s", ErrMarshalizerCreation, err.Error()) | ||
} | ||
|
||
withLogFile := ctx.GlobalBool(logSaveFile.Name) | ||
if withLogFile { | ||
var fileForLogs *os.File | ||
|
@@ -144,7 +175,7 @@ func startNode(ctx *cli.Context) error { | |
return err | ||
} | ||
|
||
messenger, err := createNode(*p2pConfig) | ||
messenger, err := createNode(*p2pConfig, internalMarshalizer) | ||
if err != nil { | ||
return err | ||
} | ||
|
@@ -172,8 +203,19 @@ func startNode(ctx *cli.Context) error { | |
} | ||
} | ||
|
||
func createNode(p2pConfig config.P2PConfig) (p2p.Messenger, error) { | ||
func loadMainConfig(filepath string) (*config.Config, error) { | ||
cfg := &config.Config{} | ||
err := core.LoadTomlFile(cfg, filepath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return cfg, nil | ||
} | ||
|
||
func createNode(p2pConfig config.P2PConfig, marshalizer marshal.Marshalizer) (p2p.Messenger, error) { | ||
arg := libp2p.ArgsNetworkMessenger{ | ||
Marshalizer: marshalizer, | ||
ListenAddress: libp2p.ListenAddrWithIp4AndTcp, | ||
P2pConfig: p2pConfig, | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add empty line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done