From 2acf1a1a6a80a82beb0f96bc1e7e30add95fe0eb Mon Sep 17 00:00:00 2001 From: Ivan Daniluk Date: Mon, 25 Sep 2017 20:22:57 +0200 Subject: [PATCH] Refactor/signals package (#359) Move signals code to the separate package. --- cmd/statusd/utils.go | 29 +++++++++++++++-------------- geth/api/backend.go | 5 +++-- geth/api/backend_jail_test.go | 13 +++++++------ geth/api/backend_test.go | 9 +++++---- geth/api/backend_txqueue_test.go | 31 ++++++++++++++++--------------- geth/jail/console/console.go | 4 ++-- geth/jail/handlers.go | 3 ++- geth/jail/jail_test.go | 5 +++-- geth/node/manager.go | 25 +++++++++++++------------ geth/node/manager_test.go | 9 +++++---- geth/node/txqueue_manager.go | 5 +++-- geth/node/utils.go | 13 +++++++------ geth/{node => signal}/signals.c | 0 geth/{node => signal}/signals.go | 14 +++++++------- 14 files changed, 88 insertions(+), 77 deletions(-) rename geth/{node => signal}/signals.c (100%) rename geth/{node => signal}/signals.go (84%) diff --git a/cmd/statusd/utils.go b/cmd/statusd/utils.go index 6e7bcf90c..19d2718ee 100644 --- a/cmd/statusd/utils.go +++ b/cmd/statusd/utils.go @@ -22,6 +22,7 @@ import ( "github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" . "github.com/status-im/status-go/geth/testing" "github.com/status-im/status-go/static" "github.com/stretchr/testify/require" @@ -738,8 +739,8 @@ func testCompleteTransaction(t *testing.T) bool { // replace transaction notification handler var txHash = "" - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope if err := json.Unmarshal([]byte(jsonEvent), &envelope); err != nil { t.Errorf("cannot unmarshal event's JSON: %s", jsonEvent) return @@ -815,9 +816,9 @@ func testCompleteMultipleQueuedTransactions(t *testing.T) bool { allTestTxCompleted := make(chan struct{}, 1) // replace transaction notification handler - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { var txID string - var envelope node.SignalEnvelope + var envelope signal.Envelope if err := json.Unmarshal([]byte(jsonEvent), &envelope); err != nil { t.Errorf("cannot unmarshal event's JSON: %s", jsonEvent) return @@ -949,8 +950,8 @@ func testDiscardTransaction(t *testing.T) bool { // replace transaction notification handler var txID string txFailedEventCalled := false - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope if err := json.Unmarshal([]byte(jsonEvent), &envelope); err != nil { t.Errorf("cannot unmarshal event's JSON: %s", jsonEvent) return @@ -1061,9 +1062,9 @@ func testDiscardMultipleQueuedTransactions(t *testing.T) bool { // replace transaction notification handler txFailedEventCallCount := 0 - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { var txID string - var envelope node.SignalEnvelope + var envelope signal.Envelope if err := json.Unmarshal([]byte(jsonEvent), &envelope); err != nil { t.Errorf("cannot unmarshal event's JSON: %s", jsonEvent) return @@ -1335,24 +1336,24 @@ func startTestNode(t *testing.T) <-chan struct{} { } waitForNodeStart := make(chan struct{}, 1) - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { t.Log(jsonEvent) - var envelope node.SignalEnvelope + var envelope signal.Envelope if err := json.Unmarshal([]byte(jsonEvent), &envelope); err != nil { t.Errorf("cannot unmarshal event's JSON: %s", jsonEvent) return } - if envelope.Type == node.EventNodeCrashed { - node.TriggerDefaultNodeNotificationHandler(jsonEvent) + if envelope.Type == signal.EventNodeCrashed { + signal.TriggerDefaultNodeNotificationHandler(jsonEvent) return } if envelope.Type == node.EventTransactionQueued { } - if envelope.Type == node.EventNodeStarted { + if envelope.Type == signal.EventNodeStarted { t.Log("Node started, but we wait till it be ready") } - if envelope.Type == node.EventNodeReady { + if envelope.Type == signal.EventNodeReady { // manually add static nodes (LES auto-discovery is not stable yet) PopulateStaticPeers() diff --git a/geth/api/backend.go b/geth/api/backend.go index 3100596d4..c46790ef4 100644 --- a/geth/api/backend.go +++ b/geth/api/backend.go @@ -10,6 +10,7 @@ import ( "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" ) // StatusBackend implements Status.im service @@ -98,8 +99,8 @@ func (m *StatusBackend) onNodeStart(nodeStarted <-chan struct{}, backendReady ch log.Info("Account reselected") close(backendReady) - node.SendSignal(node.SignalEnvelope{ - Type: node.EventNodeReady, + signal.Send(signal.Envelope{ + Type: signal.EventNodeReady, Event: struct{}{}, }) } diff --git a/geth/api/backend_jail_test.go b/geth/api/backend_jail_test.go index 4a489262c..6f5a135f8 100644 --- a/geth/api/backend_jail_test.go +++ b/geth/api/backend_jail_test.go @@ -16,6 +16,7 @@ import ( "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" . "github.com/status-im/status-go/geth/testing" "github.com/status-im/status-go/static" ) @@ -55,8 +56,8 @@ func (s *BackendTestSuite) TestJailSendQueuedTransaction() { // replace transaction notification handler requireMessageId := false - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -214,8 +215,8 @@ func (s *BackendTestSuite) TestContractDeployment() { // replace transaction notification handler var txHash gethcommon.Hash - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope var err error err = json.Unmarshal([]byte(jsonEvent), &envelope) require.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -717,8 +718,8 @@ func (s *BackendTestSuite) TestJailVMPersistence() { require.NotContains(parseResult, "error", "further will fail if initial parsing failed") var wg sync.WaitGroup - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope if err := json.Unmarshal([]byte(jsonEvent), &envelope); err != nil { s.T().Errorf("cannot unmarshal event's JSON: %s", jsonEvent) return diff --git a/geth/api/backend_test.go b/geth/api/backend_test.go index 2b93f47aa..2c377abaf 100644 --- a/geth/api/backend_test.go +++ b/geth/api/backend_test.go @@ -15,6 +15,7 @@ import ( "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" . "github.com/status-im/status-go/geth/testing" "github.com/stretchr/testify/suite" ) @@ -277,8 +278,8 @@ func (s *BackendTestSuite) TestCallRPCSendTransaction() { transactionCompleted := make(chan struct{}) var txHash gethcommon.Hash - node.SetDefaultNodeNotificationHandler(func(rawSignal string) { - var signal node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(rawSignal string) { + var signal signal.Envelope err := json.Unmarshal([]byte(rawSignal), &signal) s.NoError(err) @@ -335,8 +336,8 @@ func (s *BackendTestSuite) TestCallRPCSendTransactionUpstream() { transactionCompleted := make(chan struct{}) var txHash gethcommon.Hash - node.SetDefaultNodeNotificationHandler(func(rawSignal string) { - var signal node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(rawSignal string) { + var signal signal.Envelope err := json.Unmarshal([]byte(rawSignal), &signal) s.NoError(err) diff --git a/geth/api/backend_txqueue_test.go b/geth/api/backend_txqueue_test.go index d9e923fd9..380499200 100644 --- a/geth/api/backend_txqueue_test.go +++ b/geth/api/backend_txqueue_test.go @@ -14,6 +14,7 @@ import ( "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" . "github.com/status-im/status-go/geth/testing" ) @@ -34,8 +35,8 @@ func (s *BackendTestSuite) TestSendContractTx() { // replace transaction notification handler var txHash gethcommon.Hash - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint :dupl - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint :dupl + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -128,8 +129,8 @@ func (s *BackendTestSuite) TestSendEtherTx() { // replace transaction notification handler var txHash = gethcommon.Hash{} - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint: dupl - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint: dupl + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -208,8 +209,8 @@ func (s *BackendTestSuite) TestSendEtherTxUpstream() { // replace transaction notification handler var txHash = gethcommon.Hash{} - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint: dupl - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { // nolint: dupl + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, "cannot unmarshal JSON: %s", jsonEvent) @@ -268,8 +269,8 @@ func (s *BackendTestSuite) TestDoubleCompleteQueuedTransactions() { // replace transaction notification handler txFailedEventCalled := false txHash := gethcommon.Hash{} - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -350,8 +351,8 @@ func (s *BackendTestSuite) TestDiscardQueuedTransaction() { // replace transaction notification handler txFailedEventCalled := false - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -432,8 +433,8 @@ func (s *BackendTestSuite) TestCompleteMultipleQueuedTransactions() { allTestTxCompleted := make(chan struct{}) // replace transaction notification handler - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) @@ -533,8 +534,8 @@ func (s *BackendTestSuite) TestDiscardMultipleQueuedTransactions() { // replace transaction notification handler txFailedEventCallCount := 0 - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err) if envelope.Type == node.EventTransactionQueued { @@ -642,7 +643,7 @@ func (s *BackendTestSuite) TestNonExistentQueuedTransactions() { require.NoError(s.backend.AccountManager().SelectAccount(TestConfig.Account1.Address, TestConfig.Account1.Password)) // replace transaction notification handler - node.SetDefaultNodeNotificationHandler(func(string) {}) + signal.SetDefaultNodeNotificationHandler(func(string) {}) // try completing non-existing transaction _, err := s.backend.CompleteTransaction("some-bad-transaction-id", TestConfig.Account1.Password) diff --git a/geth/jail/console/console.go b/geth/jail/console/console.go index d8d37eb9d..e0d935213 100644 --- a/geth/jail/console/console.go +++ b/geth/jail/console/console.go @@ -6,13 +6,13 @@ import ( "strings" "github.com/robertkrimen/otto" - "github.com/status-im/status-go/geth/node" + "github.com/status-im/status-go/geth/signal" ) // Write provides the base function to write data to the underline writer // for the underline otto vm. func Write(fn otto.FunctionCall, w io.Writer, consoleEventName string) otto.Value { - node.SendSignal(node.SignalEnvelope{ + signal.Send(signal.Envelope{ Type: consoleEventName, Event: convertArgs(fn.ArgumentList), }) diff --git a/geth/jail/handlers.go b/geth/jail/handlers.go index 92a2d51a0..a77ffb481 100644 --- a/geth/jail/handlers.go +++ b/geth/jail/handlers.go @@ -7,6 +7,7 @@ import ( "github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/jail/console" "github.com/status-im/status-go/geth/node" + "github.com/status-im/status-go/geth/signal" ) // signals @@ -130,7 +131,7 @@ func makeSignalHandler(chatID string) func(call otto.FunctionCall) otto.Value { return func(call otto.FunctionCall) otto.Value { message := call.Argument(0).String() - node.SendSignal(node.SignalEnvelope{ + signal.Send(signal.Envelope{ Type: EventSignal, Event: SignalEvent{ ChatID: chatID, diff --git a/geth/jail/jail_test.go b/geth/jail/jail_test.go index 3d9b12cf4..8d19d7009 100644 --- a/geth/jail/jail_test.go +++ b/geth/jail/jail_test.go @@ -10,6 +10,7 @@ import ( "github.com/status-im/status-go/geth/jail" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" . "github.com/status-im/status-go/geth/testing" "github.com/status-im/status-go/static" "github.com/stretchr/testify/suite" @@ -232,8 +233,8 @@ func (s *JailTestSuite) TestEventSignal() { opCompletedSuccessfully := make(chan struct{}, 1) // replace transaction notification handler - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { - var envelope node.SignalEnvelope + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) require.NoError(err) diff --git a/geth/node/manager.go b/geth/node/manager.go index 4ae8b84ff..03e39f5bc 100644 --- a/geth/node/manager.go +++ b/geth/node/manager.go @@ -16,6 +16,7 @@ import ( "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/params" "github.com/status-im/status-go/geth/rpc" + "github.com/status-im/status-go/geth/signal" ) // errors @@ -82,9 +83,9 @@ func (m *NodeManager) startNode(config *params.NodeConfig) (<-chan struct{}, err m.Lock() m.nodeStarted = nil m.Unlock() - SendSignal(SignalEnvelope{ - Type: EventNodeCrashed, - Event: NodeCrashEvent{ + signal.Send(signal.Envelope{ + Type: signal.EventNodeCrashed, + Event: signal.NodeCrashEvent{ Error: fmt.Errorf("%v: %v", ErrNodeStartFailure, err).Error(), }, }) @@ -101,9 +102,9 @@ func (m *NodeManager) startNode(config *params.NodeConfig) (<-chan struct{}, err if err != nil { log.Error("Init RPC client failed:", "error", err) m.Unlock() - SendSignal(SignalEnvelope{ - Type: EventNodeCrashed, - Event: NodeCrashEvent{ + signal.Send(signal.Envelope{ + Type: signal.EventNodeCrashed, + Event: signal.NodeCrashEvent{ Error: ErrRPCClient.Error(), }, }) @@ -120,8 +121,8 @@ func (m *NodeManager) startNode(config *params.NodeConfig) (<-chan struct{}, err // notify all subscribers that Status node is started close(m.nodeStarted) - SendSignal(SignalEnvelope{ - Type: EventNodeStarted, + signal.Send(signal.Envelope{ + Type: signal.EventNodeStarted, Event: struct{}{}, }) @@ -179,8 +180,8 @@ func (m *NodeManager) stopNode() (<-chan struct{}, error) { log.Info("Node manager resets node params") // notify application that it can send more requests now - SendSignal(SignalEnvelope{ - Type: EventNodeStopped, + signal.Send(signal.Envelope{ + Type: signal.EventNodeStopped, Event: struct{}{}, }) log.Info("Node manager notifed app, that node has stopped") @@ -317,8 +318,8 @@ func (m *NodeManager) resetChainData() (<-chan struct{}, error) { return nil, err } // send signal up to native app - SendSignal(SignalEnvelope{ - Type: EventChainDataRemoved, + signal.Send(signal.Envelope{ + Type: signal.EventChainDataRemoved, Event: struct{}{}, }) log.Info("Chain data has been removed", "dir", chainDataDir) diff --git a/geth/node/manager_test.go b/geth/node/manager_test.go index 9e18013b1..65581decb 100644 --- a/geth/node/manager_test.go +++ b/geth/node/manager_test.go @@ -16,6 +16,7 @@ import ( "github.com/status-im/status-go/geth/log" "github.com/status-im/status-go/geth/node" "github.com/status-im/status-go/geth/params" + "github.com/status-im/status-go/geth/signal" . "github.com/status-im/status-go/geth/testing" "github.com/stretchr/testify/suite" ) @@ -445,13 +446,13 @@ func (s *ManagerTestSuite) TestNodeStartCrash() { // let's listen for node.crashed signal signalReceived := false - node.SetDefaultNodeNotificationHandler(func(jsonEvent string) { + signal.SetDefaultNodeNotificationHandler(func(jsonEvent string) { log.Info("Notification Received", "event", jsonEvent) - var envelope node.SignalEnvelope + var envelope signal.Envelope err := json.Unmarshal([]byte(jsonEvent), &envelope) s.NoError(err, fmt.Sprintf("cannot unmarshal JSON: %s", jsonEvent)) - if envelope.Type == node.EventNodeCrashed { + if envelope.Type == signal.EventNodeCrashed { signalReceived = true } }) @@ -478,5 +479,5 @@ func (s *ManagerTestSuite) TestNodeStartCrash() { // cleanup s.NodeManager.StopNode() - node.ResetDefaultNodeNotificationHandler() + signal.ResetDefaultNodeNotificationHandler() } diff --git a/geth/node/txqueue_manager.go b/geth/node/txqueue_manager.go index 032b53e39..7184796a8 100644 --- a/geth/node/txqueue_manager.go +++ b/geth/node/txqueue_manager.go @@ -14,6 +14,7 @@ import ( "github.com/pborman/uuid" "github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/log" + "github.com/status-im/status-go/geth/signal" ) const ( @@ -402,7 +403,7 @@ type SendTransactionEvent struct { func (m *TxQueueManager) TransactionQueueHandler() func(queuedTx *common.QueuedTx) { return func(queuedTx *common.QueuedTx) { log.Info("calling TransactionQueueHandler") - SendSignal(SignalEnvelope{ + signal.Send(signal.Envelope{ Type: EventTransactionQueued, Event: SendTransactionEvent{ ID: string(queuedTx.ID), @@ -441,7 +442,7 @@ func (m *TxQueueManager) TransactionReturnHandler() func(queuedTx *common.Queued } // error occurred, signal up to application - SendSignal(SignalEnvelope{ + signal.Send(signal.Envelope{ Type: EventTransactionFailed, Event: ReturnSendTransactionEvent{ ID: string(queuedTx.ID), diff --git a/geth/node/utils.go b/geth/node/utils.go index 8e105bfe9..c3111af03 100644 --- a/geth/node/utils.go +++ b/geth/node/utils.go @@ -3,10 +3,11 @@ package node import ( "fmt" "os" - "os/signal" + osSignal "os/signal" "github.com/status-im/status-go/geth/common" "github.com/status-im/status-go/geth/log" + "github.com/status-im/status-go/geth/signal" ) // HaltOnPanic recovers from panic, logs issue, sends upward notification, and exits @@ -15,9 +16,9 @@ func HaltOnPanic() { err := fmt.Errorf("%v: %v", ErrNodeRunFailure, r) // send signal up to native app - SendSignal(SignalEnvelope{ - Type: EventNodeCrashed, - Event: NodeCrashEvent{ + signal.Send(signal.Envelope{ + Type: signal.EventNodeCrashed, + Event: signal.NodeCrashEvent{ Error: err.Error(), }, }) @@ -29,8 +30,8 @@ func HaltOnPanic() { // HaltOnInterruptSignal stops node and panics if you press Ctrl-C enough times func HaltOnInterruptSignal(nodeManager *NodeManager) { sigc := make(chan os.Signal, 1) - signal.Notify(sigc, os.Interrupt) - defer signal.Stop(sigc) + osSignal.Notify(sigc, os.Interrupt) + defer osSignal.Stop(sigc) <-sigc if nodeManager.node == nil { return diff --git a/geth/node/signals.c b/geth/signal/signals.c similarity index 100% rename from geth/node/signals.c rename to geth/signal/signals.c diff --git a/geth/node/signals.go b/geth/signal/signals.go similarity index 84% rename from geth/node/signals.go rename to geth/signal/signals.go index f497e52d5..81769d525 100644 --- a/geth/node/signals.go +++ b/geth/signal/signals.go @@ -1,4 +1,4 @@ -package node +package signal /* #include @@ -30,8 +30,8 @@ const ( EventChainDataRemoved = "chaindata.removed" ) -// SignalEnvelope is a general signal sent upward from node to RN app -type SignalEnvelope struct { +// Envelope is a general signal sent upward from node to RN app +type Envelope struct { Type string `json:"type"` Event interface{} `json:"event"` } @@ -47,12 +47,12 @@ type NodeNotificationHandler func(jsonEvent string) var notificationHandler NodeNotificationHandler = TriggerDefaultNodeNotificationHandler -// SetDefaultNodeNotificationHandler sets notification handler to invoke on SendSignal +// SetDefaultNodeNotificationHandler sets notification handler to invoke on Send func SetDefaultNodeNotificationHandler(fn NodeNotificationHandler) { notificationHandler = fn } -// ReetDefaultNodeNotificationHandler sets notification handler to default one +// ResetDefaultNodeNotificationHandler sets notification handler to default one func ResetDefaultNodeNotificationHandler() { notificationHandler = TriggerDefaultNodeNotificationHandler } @@ -62,8 +62,8 @@ func TriggerDefaultNodeNotificationHandler(jsonEvent string) { log.Info("Notification received", "event", jsonEvent) } -// SendSignal sends application signal (JSON, normally) upwards to application (via default notification handler) -func SendSignal(signal SignalEnvelope) { +// Send sends application signal (JSON, normally) upwards to application (via default notification handler) +func Send(signal Envelope) { data, _ := json.Marshal(&signal) C.StatusServiceSignalEvent(C.CString(string(data))) }