good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
e27af97a
Commit
e27af97a
authored
May 18, 2016
by
Felix Lange
Browse files
Options
Downloads
Plain Diff
Merge pull request #2580 from fjl/p2p-config
node, p2p: move network config out of Server
parents
c8a8ad97
542b839e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
node/node.go
+3
-5
3 additions, 5 deletions
node/node.go
p2p/dial_test.go
+2
-1
2 additions, 1 deletion
p2p/dial_test.go
p2p/server.go
+8
-6
8 additions, 6 deletions
p2p/server.go
p2p/server_test.go
+23
-16
23 additions, 16 deletions
p2p/server_test.go
with
36 additions
and
28 deletions
node/node.go
+
3
−
5
View file @
e27af97a
...
@@ -49,7 +49,7 @@ type Node struct {
...
@@ -49,7 +49,7 @@ type Node struct {
datadir
string
// Path to the currently used data directory
datadir
string
// Path to the currently used data directory
eventmux
*
event
.
TypeMux
// Event multiplexer used between the services of a stack
eventmux
*
event
.
TypeMux
// Event multiplexer used between the services of a stack
serverConfig
*
p2p
.
Server
// Configuration of the underlying P2P networking layer
serverConfig
p2p
.
Config
server
*
p2p
.
Server
// Currently running P2P networking layer
server
*
p2p
.
Server
// Currently running P2P networking layer
serviceFuncs
[]
ServiceConstructor
// Service constructors (in dependency order)
serviceFuncs
[]
ServiceConstructor
// Service constructors (in dependency order)
...
@@ -97,7 +97,7 @@ func New(conf *Config) (*Node, error) {
...
@@ -97,7 +97,7 @@ func New(conf *Config) (*Node, error) {
}
}
return
&
Node
{
return
&
Node
{
datadir
:
conf
.
DataDir
,
datadir
:
conf
.
DataDir
,
serverConfig
:
&
p2p
.
Server
{
serverConfig
:
p2p
.
Config
{
PrivateKey
:
conf
.
NodeKey
(),
PrivateKey
:
conf
.
NodeKey
(),
Name
:
conf
.
Name
,
Name
:
conf
.
Name
,
Discovery
:
!
conf
.
NoDiscovery
,
Discovery
:
!
conf
.
NoDiscovery
,
...
@@ -151,9 +151,7 @@ func (n *Node) Start() error {
...
@@ -151,9 +151,7 @@ func (n *Node) Start() error {
return
ErrNodeRunning
return
ErrNodeRunning
}
}
// Otherwise copy and specialize the P2P configuration
// Otherwise copy and specialize the P2P configuration
running
:=
new
(
p2p
.
Server
)
running
:=
&
p2p
.
Server
{
Config
:
n
.
serverConfig
}
*
running
=
*
n
.
serverConfig
services
:=
make
(
map
[
reflect
.
Type
]
Service
)
services
:=
make
(
map
[
reflect
.
Type
]
Service
)
for
_
,
constructor
:=
range
n
.
serviceFuncs
{
for
_
,
constructor
:=
range
n
.
serviceFuncs
{
// Create a new context for the particular service
// Create a new context for the particular service
...
...
This diff is collapsed.
Click to expand it.
p2p/dial_test.go
+
2
−
1
View file @
e27af97a
...
@@ -478,7 +478,8 @@ func TestDialResolve(t *testing.T) {
...
@@ -478,7 +478,8 @@ func TestDialResolve(t *testing.T) {
}
}
// Now run the task, it should resolve the ID once.
// Now run the task, it should resolve the ID once.
srv
:=
&
Server
{
ntab
:
table
,
Dialer
:
&
net
.
Dialer
{
Deadline
:
time
.
Now
()
.
Add
(
-
5
*
time
.
Minute
)}}
config
:=
Config
{
Dialer
:
&
net
.
Dialer
{
Deadline
:
time
.
Now
()
.
Add
(
-
5
*
time
.
Minute
)}}
srv
:=
&
Server
{
ntab
:
table
,
Config
:
config
}
tasks
[
0
]
.
Do
(
srv
)
tasks
[
0
]
.
Do
(
srv
)
if
!
reflect
.
DeepEqual
(
table
.
resolveCalls
,
[]
discover
.
NodeID
{
dest
.
ID
})
{
if
!
reflect
.
DeepEqual
(
table
.
resolveCalls
,
[]
discover
.
NodeID
{
dest
.
ID
})
{
t
.
Fatalf
(
"wrong resolve calls, got %v"
,
table
.
resolveCalls
)
t
.
Fatalf
(
"wrong resolve calls, got %v"
,
table
.
resolveCalls
)
...
...
This diff is collapsed.
Click to expand it.
p2p/server.go
+
8
−
6
View file @
e27af97a
...
@@ -54,12 +54,8 @@ var errServerStopped = errors.New("server stopped")
...
@@ -54,12 +54,8 @@ var errServerStopped = errors.New("server stopped")
var
srvjslog
=
logger
.
NewJsonLogger
()
var
srvjslog
=
logger
.
NewJsonLogger
()
// Server manages all peer connections.
// Config holds Server options.
//
type
Config
struct
{
// The fields of Server are used as configuration parameters.
// You should set them before starting the Server. Fields may not be
// modified while the server is running.
type
Server
struct
{
// This field must be set to a valid secp256k1 private key.
// This field must be set to a valid secp256k1 private key.
PrivateKey
*
ecdsa
.
PrivateKey
PrivateKey
*
ecdsa
.
PrivateKey
...
@@ -120,6 +116,12 @@ type Server struct {
...
@@ -120,6 +116,12 @@ type Server struct {
// If NoDial is true, the server will not dial any peers.
// If NoDial is true, the server will not dial any peers.
NoDial
bool
NoDial
bool
}
// Server manages all peer connections.
type
Server
struct
{
// Config fields may not be modified while the server is running.
Config
// Hooks for testing. These are useful because we can inhibit
// Hooks for testing. These are useful because we can inhibit
// the whole protocol stack.
// the whole protocol stack.
...
...
This diff is collapsed.
Click to expand it.
p2p/server_test.go
+
23
−
16
View file @
e27af97a
...
@@ -67,11 +67,14 @@ func (c *testTransport) close(err error) {
...
@@ -67,11 +67,14 @@ func (c *testTransport) close(err error) {
}
}
func
startTestServer
(
t
*
testing
.
T
,
id
discover
.
NodeID
,
pf
func
(
*
Peer
))
*
Server
{
func
startTestServer
(
t
*
testing
.
T
,
id
discover
.
NodeID
,
pf
func
(
*
Peer
))
*
Server
{
server
:=
&
Server
{
config
:=
Config
{
Name
:
"test"
,
Name
:
"test"
,
MaxPeers
:
10
,
MaxPeers
:
10
,
ListenAddr
:
"127.0.0.1:0"
,
ListenAddr
:
"127.0.0.1:0"
,
PrivateKey
:
newkey
(),
PrivateKey
:
newkey
(),
}
server
:=
&
Server
{
Config
:
config
,
newPeerHook
:
pf
,
newPeerHook
:
pf
,
newTransport
:
func
(
fd
net
.
Conn
)
transport
{
return
newTestTransport
(
id
,
fd
)
},
newTransport
:
func
(
fd
net
.
Conn
)
transport
{
return
newTestTransport
(
id
,
fd
)
},
}
}
...
@@ -200,7 +203,7 @@ func TestServerTaskScheduling(t *testing.T) {
...
@@ -200,7 +203,7 @@ func TestServerTaskScheduling(t *testing.T) {
// The Server in this test isn't actually running
// The Server in this test isn't actually running
// because we're only interested in what run does.
// because we're only interested in what run does.
srv
:=
&
Server
{
srv
:=
&
Server
{
MaxPeers
:
10
,
Config
:
Config
{
MaxPeers
:
10
}
,
quit
:
make
(
chan
struct
{}),
quit
:
make
(
chan
struct
{}),
ntab
:
fakeTable
{},
ntab
:
fakeTable
{},
running
:
true
,
running
:
true
,
...
@@ -314,10 +317,12 @@ func (t *testTask) Do(srv *Server) {
...
@@ -314,10 +317,12 @@ func (t *testTask) Do(srv *Server) {
func
TestServerAtCap
(
t
*
testing
.
T
)
{
func
TestServerAtCap
(
t
*
testing
.
T
)
{
trustedID
:=
randomID
()
trustedID
:=
randomID
()
srv
:=
&
Server
{
srv
:=
&
Server
{
Config
:
Config
{
PrivateKey
:
newkey
(),
PrivateKey
:
newkey
(),
MaxPeers
:
10
,
MaxPeers
:
10
,
NoDial
:
true
,
NoDial
:
true
,
TrustedNodes
:
[]
*
discover
.
Node
{{
ID
:
trustedID
}},
TrustedNodes
:
[]
*
discover
.
Node
{{
ID
:
trustedID
}},
},
}
}
if
err
:=
srv
.
Start
();
err
!=
nil
{
if
err
:=
srv
.
Start
();
err
!=
nil
{
t
.
Fatalf
(
"could not start: %v"
,
err
)
t
.
Fatalf
(
"could not start: %v"
,
err
)
...
@@ -415,10 +420,12 @@ func TestServerSetupConn(t *testing.T) {
...
@@ -415,10 +420,12 @@ func TestServerSetupConn(t *testing.T) {
for
i
,
test
:=
range
tests
{
for
i
,
test
:=
range
tests
{
srv
:=
&
Server
{
srv
:=
&
Server
{
Config
:
Config
{
PrivateKey
:
srvkey
,
PrivateKey
:
srvkey
,
MaxPeers
:
10
,
MaxPeers
:
10
,
NoDial
:
true
,
NoDial
:
true
,
Protocols
:
[]
Protocol
{
discard
},
Protocols
:
[]
Protocol
{
discard
},
},
newTransport
:
func
(
fd
net
.
Conn
)
transport
{
return
test
.
tt
},
newTransport
:
func
(
fd
net
.
Conn
)
transport
{
return
test
.
tt
},
}
}
if
!
test
.
dontstart
{
if
!
test
.
dontstart
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment