diff --git a/gql_test.go b/gql_test.go index 5e52da4..d8abb3a 100644 --- a/gql_test.go +++ b/gql_test.go @@ -19,7 +19,7 @@ import ( func TestGQLSubscribe(t *testing.T) { ctx := logTestContext(t, []string{"test", "gql"}) - n1, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt(nil)) + n1, err := NewNode(ctx, nil, "LockableNode", NewLockableExt(nil)) fatalErr(t, err) listener_ext := NewListenerExt(10) @@ -27,7 +27,7 @@ func TestGQLSubscribe(t *testing.T) { gql_ext, err := NewGQLExt(ctx, ":0", nil, nil) fatalErr(t, err) - gql, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt([]NodeID{n1.ID}), gql_ext, listener_ext) + gql, err := NewNode(ctx, nil, "LockableNode", NewLockableExt([]NodeID{n1.ID}), gql_ext, listener_ext) fatalErr(t, err) query := "subscription { Self { ID, Type ... on Lockable { LockableState } } }" @@ -129,14 +129,14 @@ func TestGQLQuery(t *testing.T) { ctx := logTestContext(t, []string{"test", "lockable"}) n1_listener := NewListenerExt(10) - n1, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt(nil), n1_listener) + n1, err := NewNode(ctx, nil, "LockableNode", NewLockableExt(nil), n1_listener) fatalErr(t, err) gql_listener := NewListenerExt(10) gql_ext, err := NewGQLExt(ctx, ":0", nil, nil) fatalErr(t, err) - gql, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt([]NodeID{n1.ID}), gql_ext, gql_listener) + gql, err := NewNode(ctx, nil, "LockableNode", NewLockableExt([]NodeID{n1.ID}), gql_ext, gql_listener) fatalErr(t, err) ctx.Log.Logf("test", "GQL: %s", gql.ID) @@ -208,7 +208,7 @@ func TestGQLDB(t *testing.T) { fatalErr(t, err) listener_ext := NewListenerExt(10) - gql, err := NewNode(ctx, nil, "Node", 10, gql_ext, listener_ext) + gql, err := NewNode(ctx, nil, "Node", gql_ext, listener_ext) fatalErr(t, err) ctx.Log.Logf("test", "GQL_ID: %s", gql.ID) diff --git a/graph_test.go b/graph_test.go index c823ff6..e404565 100644 --- a/graph_test.go +++ b/graph_test.go @@ -12,7 +12,6 @@ func NewSimpleListener(ctx *Context, buffer int) (*Node, *ListenerExt, error) { listener, err := NewNode(ctx, nil, "LockableNode", - 10, nil, listener_extension, NewLockableExt(nil)) diff --git a/lockable_test.go b/lockable_test.go index 4a46053..9b58ba9 100644 --- a/lockable_test.go +++ b/lockable_test.go @@ -10,12 +10,12 @@ func TestLink(t *testing.T) { l2_listener := NewListenerExt(10) - l2, err := NewNode(ctx, nil, "LockableNode", 10, l2_listener, NewLockableExt(nil)) + l2, err := NewNode(ctx, nil, "LockableNode", l2_listener, NewLockableExt(nil)) fatalErr(t, err) l1_lockable := NewLockableExt(nil) l1_listener := NewListenerExt(10) - l1, err := NewNode(ctx, nil, "LockableNode", 10, l1_listener, l1_lockable) + l1, err := NewNode(ctx, nil, "LockableNode", l1_listener, l1_lockable) fatalErr(t, err) link_signal := NewLinkSignal("add", l2.ID) @@ -62,7 +62,7 @@ func testLockN(t *testing.T, n int) { ctx := logTestContext(t, []string{"test"}) NewLockable := func()(*Node) { - l, err := NewNode(ctx, nil, "LockableNode", 10, NewLockableExt(nil)) + l, err := NewNode(ctx, nil, "LockableNode", NewLockableExt(nil)) fatalErr(t, err) return l } @@ -75,7 +75,7 @@ func testLockN(t *testing.T, n int) { ctx.Log.Logf("test", "CREATED_%d", n) listener := NewListenerExt(50000) - node, err := NewNode(ctx, nil, "LockableNode", 500000, listener, NewLockableExt(reqs)) + node, err := NewNode(ctx, nil, "LockableNode", listener, NewLockableExt(reqs)) fatalErr(t, err) ctx.Log.Logf("test", "CREATED_LISTENER") @@ -99,7 +99,7 @@ func TestLock(t *testing.T) { NewLockable := func(reqs []NodeID)(*Node, *ListenerExt) { listener := NewListenerExt(10000) - l, err := NewNode(ctx, nil, "LockableNode", 10, listener, NewLockableExt(reqs)) + l, err := NewNode(ctx, nil, "LockableNode", listener, NewLockableExt(reqs)) fatalErr(t, err) return l, listener } diff --git a/node.go b/node.go index 4f0a404..1a6b888 100644 --- a/node.go +++ b/node.go @@ -72,6 +72,8 @@ func (q QueuedSignal) String() string { type WaitMap map[uuid.UUID]NodeID +const NODE_INITIAL_QUEUE_SIZE = 2 + // Nodes represent a group of extensions that can be collectively addressed type Node struct { Key ed25519.PrivateKey `gv:"key"` @@ -99,7 +101,7 @@ func (node *Node) PostDeserialize(ctx *Context) error { public := node.Key.Public().(ed25519.PublicKey) node.ID = KeyID(public) - node.SendChan, node.RecvChan = NewMessageQueue(1000) + node.SendChan, node.RecvChan = NewMessageQueue(NODE_INITIAL_QUEUE_SIZE) return nil } @@ -398,7 +400,7 @@ func KeyID(pub ed25519.PublicKey) NodeID { } // Create a new node in memory and start it's event loop -func NewNode(ctx *Context, key ed25519.PrivateKey, type_name string, buffer_size uint32, extensions ...Extension) (*Node, error) { +func NewNode(ctx *Context, key ed25519.PrivateKey, type_name string, extensions ...Extension) (*Node, error) { node_type := NodeTypeFor(type_name) node_info, known_type := ctx.NodeTypes[node_type] if known_type == false { @@ -454,7 +456,7 @@ func NewNode(ctx *Context, key ed25519.PrivateKey, type_name string, buffer_size writeSignalQueue: false, } - node.SendChan, node.RecvChan = NewMessageQueue(1000) + node.SendChan, node.RecvChan = NewMessageQueue(NODE_INITIAL_QUEUE_SIZE) err = ctx.DB.WriteNodeInit(ctx, node) if err != nil { diff --git a/node_test.go b/node_test.go index a7445b3..e9a3962 100644 --- a/node_test.go +++ b/node_test.go @@ -12,7 +12,7 @@ func TestNodeDB(t *testing.T) { ctx := logTestContext(t, []string{"test", "node", "db"}) node_listener := NewListenerExt(10) - node, err := NewNode(ctx, nil, "Node", 10, NewLockableExt(nil), node_listener) + node, err := NewNode(ctx, nil, "Node", NewLockableExt(nil), node_listener) fatalErr(t, err) _, err = WaitForSignal(node_listener.Chan, 10*time.Millisecond, func(sig *StatusSignal) bool { @@ -41,10 +41,10 @@ func TestNodeRead(t *testing.T) { ctx.Log.Logf("test", "N2: %s", n2_id) n2_listener := NewListenerExt(10) - n2, err := NewNode(ctx, n2_key, "Node", 10, n2_listener) + n2, err := NewNode(ctx, n2_key, "Node", n2_listener) fatalErr(t, err) - n1, err := NewNode(ctx, n1_key, "Node", 10, NewListenerExt(10)) + n1, err := NewNode(ctx, n1_key, "Node", NewListenerExt(10)) fatalErr(t, err) read_sig := NewReadSignal([]string{"buffer"}) diff --git a/serialize_test.go b/serialize_test.go index f35bda8..6e17a13 100644 --- a/serialize_test.go +++ b/serialize_test.go @@ -170,7 +170,7 @@ func TestSerializeValues(t *testing.T) { testSerialize(t, ctx, NewListenerExt(10)) - node, err := NewNode(ctx, nil, "Node", 100) + node, err := NewNode(ctx, nil, "Node") fatalErr(t, err) testSerialize(t, ctx, node) }