aboutsummaryrefslogtreecommitdiff
path: root/node
diff options
context:
space:
mode:
authorDeterminant <[email protected]>2020-09-16 19:00:25 -0400
committerDeterminant <[email protected]>2020-09-16 19:00:25 -0400
commitb1ac5e6ce73c37378e575d6291e3c5f1ee170430 (patch)
tree842889ed69fcf55a3dd3a0226e44ad54025d6a79 /node
parent8478802ddacc027a8d8c866da9365f6739d9d9d4 (diff)
build success
Diffstat (limited to 'node')
-rw-r--r--node/api.go1
-rw-r--r--node/node.go34
2 files changed, 32 insertions, 3 deletions
diff --git a/node/api.go b/node/api.go
index e74d10b..4589d25 100644
--- a/node/api.go
+++ b/node/api.go
@@ -21,6 +21,7 @@ import (
"fmt"
//"strings"
+ "github.com/ava-labs/coreth/internal/debug"
"github.com/ava-labs/coreth/rpc"
"github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto"
diff --git a/node/node.go b/node/node.go
index c6e4181..3ed89ed 100644
--- a/node/node.go
+++ b/node/node.go
@@ -18,14 +18,13 @@ package node
import (
"errors"
+ "os"
"path/filepath"
- "reflect"
"strings"
"sync"
"github.com/ava-labs/coreth/accounts"
"github.com/ava-labs/coreth/core/rawdb"
- "github.com/ava-labs/coreth/internal/debug"
"github.com/ava-labs/coreth/rpc"
"github.com/ethereum/go-ethereum/ethdb"
"github.com/ethereum/go-ethereum/event"
@@ -48,7 +47,6 @@ type Node struct {
state int // Tracks state of node lifecycle
lock sync.Mutex
- lifecycles []Lifecycle // All registered backends, services, and auxiliary services that have a lifecycle
rpcAPIs []rpc.API // List of APIs currently provided by the node
inprocHandler *rpc.Server // In-process RPC request handler to process the API requests
@@ -61,6 +59,25 @@ const (
closedState
)
+func (n *Node) openDataDir() error {
+ if n.config.DataDir == "" {
+ return nil // ephemeral
+ }
+
+ instdir := filepath.Join(n.config.DataDir, n.config.name())
+ if err := os.MkdirAll(instdir, 0700); err != nil {
+ return err
+ }
+ // Lock the instance directory to prevent concurrent use by another instance as well as
+ // accidental use of the instance directory as a database.
+ release, _, err := fileutil.Flock(filepath.Join(instdir, "LOCK"))
+ if err != nil {
+ return convertFileLockError(err)
+ }
+ n.dirLock = release
+ return nil
+}
+
// New creates a new P2P node, ready for protocol registration.
func New(conf *Config) (*Node, error) {
// Copy config and resolve the datadir so future changes to the current
@@ -266,3 +283,14 @@ func (n *Node) closeDatabases() (errors []error) {
}
return errors
}
+
+// RegisterAPIs registers the APIs a service provides on the node.
+func (n *Node) RegisterAPIs(apis []rpc.API) {
+ n.lock.Lock()
+ defer n.lock.Unlock()
+
+ if n.state != initializingState {
+ panic("can't register APIs on running/stopped node")
+ }
+ n.rpcAPIs = append(n.rpcAPIs, apis...)
+}