Skip to content

Commit

Permalink
new config for ipv6 related changes
Browse files Browse the repository at this point in the history
  • Loading branch information
shotasilagadzetaal committed Oct 28, 2024
1 parent bee811e commit 8968c28
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 29 deletions.
4 changes: 2 additions & 2 deletions cmd/arc/services/blocktx.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,11 +127,11 @@ func StartBlockTx(logger *slog.Logger, arcConfig *config.ArcConfig) (func(), err
}

pm = p2p.NewPeerManager(logger.With(slog.String("module", "peer-mng")), network, pmOpts...)
peers := make([]p2p.PeerI, len(arcConfig.Peers))
peers := make([]p2p.PeerI, len(arcConfig.Broadcasting.Peers))

peerHandler := blocktx.NewPeerHandler(logger, blockRequestCh, blockProcessCh)

for i, peerSetting := range arcConfig.Peers {
for i, peerSetting := range arcConfig.Broadcasting.Peers {
peerURL, err := peerSetting.GetP2PUrl()
if err != nil {
stopFn()
Expand Down
4 changes: 2 additions & 2 deletions cmd/arc/services/metamorph.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ func StartMetamorph(logger *slog.Logger, arcConfig *config.ArcConfig, cacheStore
return nil, fmt.Errorf("serve GRPC server failed: %v", err)
}

for i, peerSetting := range arcConfig.Peers {
for i, peerSetting := range arcConfig.Broadcasting.Peers {
zmqURL, err := peerSetting.GetZMQUrl()
if err != nil {
logger.Warn("failed to get zmq URL for peer", slog.Int("index", i), slog.String("err", err.Error()))
Expand Down Expand Up @@ -264,7 +264,7 @@ func initPeerManager(logger *slog.Logger, s store.MetamorphStore, arcConfig *con
peerOpts = append(peerOpts, p2p.WithUserAgent("ARC", version.Version))
}

for _, peerSetting := range arcConfig.Peers {
for _, peerSetting := range arcConfig.Broadcasting.Peers {
peerUrl, err := peerSetting.GetP2PUrl()
if err != nil {
return nil, nil, nil, fmt.Errorf("error getting peer url: %v", err)
Expand Down
20 changes: 14 additions & 6 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type ArcConfig struct {
MessageQueue *MessageQueueConfig `mapstructure:"messageQueue"`
Tracing *TracingConfig `mapstructure:"tracing"`
PeerRpc *PeerRpcConfig `mapstructure:"peerRpc"`
Peers []*PeerConfig `mapstructure:"peers"`
Broadcasting *BroadcastingConfig `mapstructure:"broadcasting"`
Metamorph *MetamorphConfig `mapstructure:"metamorph"`
Blocktx *BlocktxConfig `mapstructure:"blocktx"`
Api *ApiConfig `mapstructure:"api"`
Expand All @@ -31,6 +31,19 @@ type ArcConfig struct {
Cache *CacheConfig `mapstructure:"cache"`
}

type BroadcastingConfig struct {
Mode string `mapstructure:"mode"`
Ipv6Enabled bool `mapstructure:"ipv6Enabled"`
MulticastGroup string `mapstructure:"multicastGroup"`
Peers []*PeerConfig `mapstructure:"peers"`
Interfaces []*string `mapstructure:"interfaces"`
}

type PeerConfig struct {
Host string `mapstructure:"host"`
Port *PeerPortConfig `mapstructure:"port"`
}

type MessageQueueConfig struct {
URL string `mapstructure:"url"`
Streaming MessageQueueStreaming `mapstructure:"streaming"`
Expand All @@ -52,11 +65,6 @@ type PeerRpcConfig struct {
Port int `mapstructure:"port"`
}

type PeerConfig struct {
Host string `mapstructure:"host"`
Port *PeerPortConfig `mapstructure:"port"`
}

type PeerPortConfig struct {
P2P int `mapstructure:"p2p"`
ZMQ int `mapstructure:"zmq"`
Expand Down
42 changes: 24 additions & 18 deletions config/defaults.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func getDefaultArcConfig() *ArcConfig {
MessageQueue: getDefaultMessageQueueConfig(),
Tracing: nil, // optional
PeerRpc: getDefaultPeerRpcConfig(),
Peers: getPeersConfig(),
Broadcasting: getPeersConfig(),
Metamorph: getMetamorphConfig(),
Blocktx: getBlocktxConfig(),
Api: getApiConfig(),
Expand Down Expand Up @@ -47,25 +47,31 @@ func getDefaultPeerRpcConfig() *PeerRpcConfig {
}
}

func getPeersConfig() []*PeerConfig {
return []*PeerConfig{
{
Host: "localhost",
Port: &PeerPortConfig{
P2P: 18333,
ZMQ: 28332,
func getPeersConfig() *BroadcastingConfig {
return &BroadcastingConfig{
Mode: "unicast",
Ipv6Enabled: false,
MulticastGroup: "",
Interfaces: nil,
Peers: []*PeerConfig{
{
Host: "localhost",
Port: &PeerPortConfig{
P2P: 18333,
ZMQ: 28332,
},
},
},
{
Host: "localhost",
Port: &PeerPortConfig{
P2P: 18334,
{
Host: "localhost",
Port: &PeerPortConfig{
P2P: 18334,
},
},
},
{
Host: "localhost",
Port: &PeerPortConfig{
P2P: 18335,
{
Host: "localhost",
Port: &PeerPortConfig{
P2P: 18335,
},
},
},
}
Expand Down
10 changes: 9 additions & 1 deletion config/example_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ peerRpc: # rpc configuration for bitcoin node
host: localhost
port: 18332

peers: # list of bitcoin node peers to connect to
broadcasting:
mode: unicast
ipv6Enabled: true
multicastGroup: 172.28.56.77
peers: # list of bitcoin node peers to connect to
- host: localhost
port:
p2p: 18333 # port for p2p connection
Expand All @@ -31,6 +35,10 @@ peers: # list of bitcoin node peers to connect to
- host: localhost
port:
p2p: 18335
interfaces:
- "eth0"
- "eth1"


cache:
engine: freecache # cache engine - freecache/redis
Expand Down
5 changes: 5 additions & 0 deletions config/load_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ func Test_Load(t *testing.T) {
assert.Equal(t, "INFO", actualConfig.LogLevel)
assert.Equal(t, "text", actualConfig.LogFormat)
assert.Equal(t, "mainnet", actualConfig.Network)
assert.Equal(t, 18335, actualConfig.Broadcasting.Peers[2].Port.P2P)
assert.Equal(t, "172.28.56.77", actualConfig.Broadcasting.MulticastGroup)
assert.Equal(t, true, actualConfig.Broadcasting.Ipv6Enabled)
assert.Equal(t, "unicast", actualConfig.Broadcasting.Mode)
assert.Equal(t, "eth1", *actualConfig.Broadcasting.Interfaces[1])
assert.NotNil(t, actualConfig.Tracing)
assert.Equal(t, "http://tracing:1234", actualConfig.Tracing.DialAddr)
})
Expand Down
18 changes: 18 additions & 0 deletions config/test_files/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,21 @@ logFormat: text
network: mainnet
tracing:
dialAddr: http://tracing:1234
broadcasting:
mode: unicast
ipv6Enabled: true
multicastGroup: 172.28.56.77
peers: # list of bitcoin node peers to connect to
- host: localhost
port:
p2p: 18333 # port for p2p connection
zmq: 28332 # port for zmq connection
- host: localhost
port:
p2p: 18334
- host: localhost
port:
p2p: 18335
interfaces:
- "eth0"
- "eth1"

0 comments on commit 8968c28

Please sign in to comment.