Skip to content

Commit 7014fc8

Browse files
author
Tyler Smith
committed
TWEAK: Add CLI flag for IPCs path.
1 parent d5ccfc8 commit 7014fc8

File tree

5 files changed

+32
-16
lines changed

5 files changed

+32
-16
lines changed

ipcs/chainipc.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,36 @@ import (
1313
)
1414

1515
const (
16-
defaultBaseURL = "/tmp"
16+
DefaultBaseURL = "/tmp"
1717

1818
ipcIdentifierPrefix = "ipc"
1919
ipcConsensusIdentifier = "consensus"
2020
ipcDecisionsIdentifier = "decisions"
2121
)
2222

23+
type context struct {
24+
log logging.Logger
25+
networkID uint32
26+
path string
27+
}
28+
2329
// ChainIPCs maintains IPCs for a set of chains
2430
type ChainIPCs struct {
25-
log logging.Logger
26-
networkID uint32
31+
context
2732
chains map[[32]byte]*eventSockets
2833
consensusEvents *triggers.EventDispatcher
2934
decisionEvents *triggers.EventDispatcher
3035
}
3136

3237
// NewChainIPCs creates a new *ChainIPCs that writes consensus and decision
3338
// events to IPC sockets
34-
func NewChainIPCs(log logging.Logger, networkID uint32, consensusEvents *triggers.EventDispatcher, decisionEvents *triggers.EventDispatcher, defaultChainIDs []ids.ID) (*ChainIPCs, error) {
39+
func NewChainIPCs(log logging.Logger, path string, networkID uint32, consensusEvents *triggers.EventDispatcher, decisionEvents *triggers.EventDispatcher, defaultChainIDs []ids.ID) (*ChainIPCs, error) {
3540
cipcs := &ChainIPCs{
36-
log: log,
37-
networkID: networkID,
41+
context: context{
42+
log: log,
43+
networkID: networkID,
44+
path: path,
45+
},
3846
chains: make(map[[32]byte]*eventSockets),
3947
consensusEvents: consensusEvents,
4048
decisionEvents: decisionEvents,
@@ -56,7 +64,7 @@ func (cipcs *ChainIPCs) Publish(chainID ids.ID) (*eventSockets, error) {
5664
return es, nil
5765
}
5866

59-
es, err := newEventSockets(cipcs.log, cipcs.networkID, chainID, cipcs.consensusEvents, cipcs.decisionEvents)
67+
es, err := newEventSockets(cipcs.context, chainID, cipcs.consensusEvents, cipcs.decisionEvents)
6068
if err != nil {
6169
cipcs.log.Error("can't create ipcs: %s", err)
6270
return nil, err
@@ -77,6 +85,6 @@ func (cipcs *ChainIPCs) Unpublish(chainID ids.ID) (bool, error) {
7785
return true, chainIPCs.stop()
7886
}
7987

80-
func ipcURL(base string, networkID uint32, chainID ids.ID, eventType string) string {
81-
return path.Join(base, fmt.Sprintf("%d-%s-%s", networkID, chainID.String(), eventType))
88+
func ipcURL(ctx context, chainID ids.ID, eventType string) string {
89+
return path.Join(ctx.path, fmt.Sprintf("%d-%s-%s", ctx.networkID, chainID.String(), eventType))
8290
}

ipcs/eventsocket.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,25 @@ import (
1414
"github.com/ava-labs/gecko/utils/wrappers"
1515
)
1616

17+
type chainEventDipatcher struct {
18+
chainID ids.ID
19+
events *triggers.EventDispatcher
20+
}
21+
1722
// eventSockets is a set of named eventSockets
1823
type eventSockets struct {
1924
consensusSocket *eventSocket
2025
decisionsSocket *eventSocket
2126
}
2227

2328
// newEventSockets creates a *ChainIPCs with both consensus and decisions IPCs
24-
func newEventSockets(log logging.Logger, networkID uint32, chainID ids.ID, consensusEvents *triggers.EventDispatcher, decisionEvents *triggers.EventDispatcher) (*eventSockets, error) {
25-
consensusIPC, err := newEventIPCSocket(log, networkID, chainID, ipcConsensusIdentifier, consensusEvents)
29+
func newEventSockets(ctx context, chainID ids.ID, consensusEvents *triggers.EventDispatcher, decisionEvents *triggers.EventDispatcher) (*eventSockets, error) {
30+
consensusIPC, err := newEventIPCSocket(ctx, chainID, ipcConsensusIdentifier, consensusEvents)
2631
if err != nil {
2732
return nil, err
2833
}
2934

30-
decisionsIPC, err := newEventIPCSocket(log, networkID, chainID, ipcDecisionsIdentifier, decisionEvents)
35+
decisionsIPC, err := newEventIPCSocket(ctx, chainID, ipcDecisionsIdentifier, decisionEvents)
3136
if err != nil {
3237
return nil, err
3338
}
@@ -90,7 +95,7 @@ type eventSocket struct {
9095

9196
// newEventIPCSocket creates a *eventSocket for the given chain and
9297
// EventDispatcher that writes to a local IPC socket
93-
func newEventIPCSocket(log logging.Logger, networkID uint32, chainID ids.ID, name string, events *triggers.EventDispatcher) (*eventSocket, error) {
98+
func newEventIPCSocket(ctx context, chainID ids.ID, name string, events *triggers.EventDispatcher) (*eventSocket, error) {
9499
sock, err := pub.NewSocket()
95100
if err != nil {
96101
return nil, err
@@ -99,9 +104,9 @@ func newEventIPCSocket(log logging.Logger, networkID uint32, chainID ids.ID, nam
99104
ipcName := ipcIdentifierPrefix + "-" + name
100105

101106
eis := &eventSocket{
102-
log: log,
107+
log: ctx.log,
103108
socket: sock,
104-
url: ipcURL(defaultBaseURL, networkID, chainID, name),
109+
url: ipcURL(ctx, chainID, name),
105110
unregisterFn: func() error {
106111
return events.DeregisterChain(chainID, ipcName)
107112
},

main/params.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"github.com/ava-labs/gecko/database/memdb"
1818
"github.com/ava-labs/gecko/genesis"
1919
"github.com/ava-labs/gecko/ids"
20+
"github.com/ava-labs/gecko/ipcs"
2021
"github.com/ava-labs/gecko/nat"
2122
"github.com/ava-labs/gecko/node"
2223
"github.com/ava-labs/gecko/snow/networking/router"
@@ -240,6 +241,7 @@ func init() {
240241

241242
// IPC
242243
ipcsChainIDs := fs.String("ipcs-chain-ids", "", "Comma separated list of chain ids to add to the IPC engine. Example: 11111111111111111111111111111111LpoYY,4R5p2RXDGLqaifZE4hHWH9owe34pfoBULn1DrQTWivjg8o4aH")
244+
fs.StringVar(&Config.IPCPath, "ipcs-path", ipcs.DefaultBaseURL, "The directory (Unix) or named pipe name prefix (Windows) for IPC sockets")
243245

244246
ferr := fs.Parse(os.Args[1:])
245247

node/config.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ type Config struct {
7272

7373
// IPC configuration
7474
IPCAPIEnabled bool
75+
IPCPath string
7576
IPCDefaultChainIDs []string
7677

7778
// Router that is used to handle incoming consensus messages

node/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func (n *Node) initIPCs() error {
346346
}
347347

348348
var err error
349-
n.IPCs, err = ipcs.NewChainIPCs(n.Log, n.Config.NetworkID, n.ConsensusDispatcher, n.DecisionDispatcher, chainIDs)
349+
n.IPCs, err = ipcs.NewChainIPCs(n.Log, n.Config.IPCPath, n.Config.NetworkID, n.ConsensusDispatcher, n.DecisionDispatcher, chainIDs)
350350
return err
351351
}
352352

0 commit comments

Comments
 (0)