Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
Geth-Modification
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
张蕾
Geth-Modification
Commits
509389be
Commit
509389be
authored
Jun 18, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'develop' of github.com-obscure:ethereum/eth-go into develop
parents
f911087e
d179f31d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
12 deletions
+36
-12
ethereum.go
ethereum.go
+4
-10
peer.go
peer.go
+32
-2
No files found.
ethereum.go
View file @
509389be
...
@@ -149,7 +149,9 @@ func (s *Ethereum) IsUpToDate() bool {
...
@@ -149,7 +149,9 @@ func (s *Ethereum) IsUpToDate() bool {
})
})
return
upToDate
return
upToDate
}
}
func
(
s
*
Ethereum
)
PushPeer
(
peer
*
Peer
)
{
s
.
peers
.
PushBack
(
peer
)
}
func
(
s
*
Ethereum
)
IsListening
()
bool
{
func
(
s
*
Ethereum
)
IsListening
()
bool
{
return
s
.
listening
return
s
.
listening
}
}
...
@@ -159,14 +161,11 @@ func (s *Ethereum) AddPeer(conn net.Conn) {
...
@@ -159,14 +161,11 @@ func (s *Ethereum) AddPeer(conn net.Conn) {
if
peer
!=
nil
{
if
peer
!=
nil
{
if
s
.
peers
.
Len
()
<
s
.
MaxPeers
{
if
s
.
peers
.
Len
()
<
s
.
MaxPeers
{
s
.
peers
.
PushBack
(
peer
)
peer
.
Start
()
peer
.
Start
()
}
else
{
}
else
{
ethutil
.
Config
.
Log
.
Debugf
(
"[SERV] Max connected peers reached. Not adding incoming peer."
)
ethutil
.
Config
.
Log
.
Debugf
(
"[SERV] Max connected peers reached. Not adding incoming peer."
)
}
}
}
}
s
.
reactor
.
Post
(
"peerList"
,
s
.
peers
)
}
}
func
(
s
*
Ethereum
)
ProcessPeerList
(
addrs
[]
string
)
{
func
(
s
*
Ethereum
)
ProcessPeerList
(
addrs
[]
string
)
{
...
@@ -233,12 +232,7 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
...
@@ -233,12 +232,7 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
return
nil
return
nil
}
}
peer
:=
NewOutboundPeer
(
addr
,
s
,
s
.
serverCaps
)
NewOutboundPeer
(
addr
,
s
,
s
.
serverCaps
)
s
.
peers
.
PushBack
(
peer
)
ethutil
.
Config
.
Log
.
Infof
(
"[SERV] Adding peer (%s) %d / %d
\n
"
,
addr
,
s
.
peers
.
Len
(),
s
.
MaxPeers
)
s
.
reactor
.
Post
(
"peerList"
,
s
.
peers
)
}
}
return
nil
return
nil
...
...
peer.go
View file @
509389be
...
@@ -2,6 +2,7 @@ package eth
...
@@ -2,6 +2,7 @@ package eth
import
(
import
(
"bytes"
"bytes"
"container/list"
"fmt"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
...
@@ -124,6 +125,7 @@ type Peer struct {
...
@@ -124,6 +125,7 @@ type Peer struct {
port
uint16
port
uint16
caps
Caps
caps
Caps
// This peer's public key
pubkey
[]
byte
pubkey
[]
byte
// Indicated whether the node is catching up or not
// Indicated whether the node is catching up or not
...
@@ -171,7 +173,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
...
@@ -171,7 +173,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
// Set up the connection in another goroutine so we don't block the main thread
// Set up the connection in another goroutine so we don't block the main thread
go
func
()
{
go
func
()
{
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
3
0
*
time
.
Second
)
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
1
0
*
time
.
Second
)
if
err
!=
nil
{
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Debugln
(
"Connection to peer failed"
,
err
)
ethutil
.
Config
.
Log
.
Debugln
(
"Connection to peer failed"
,
err
)
...
@@ -614,6 +616,30 @@ func (p *Peer) pushPeers() {
...
@@ -614,6 +616,30 @@ func (p *Peer) pushPeers() {
func
(
p
*
Peer
)
handleHandshake
(
msg
*
ethwire
.
Msg
)
{
func
(
p
*
Peer
)
handleHandshake
(
msg
*
ethwire
.
Msg
)
{
c
:=
msg
.
Data
c
:=
msg
.
Data
// Set pubkey
p
.
pubkey
=
c
.
Get
(
5
)
.
Bytes
()
if
p
.
pubkey
==
nil
{
//ethutil.Config.Log.Debugln("Pubkey required, not supplied in handshake.")
p
.
Stop
()
return
}
usedPub
:=
0
// This peer is already added to the peerlist so we expect to find a double pubkey at least once
eachPeer
(
p
.
ethereum
.
Peers
(),
func
(
peer
*
Peer
,
e
*
list
.
Element
)
{
if
bytes
.
Compare
(
p
.
pubkey
,
peer
.
pubkey
)
==
0
{
usedPub
++
}
})
if
usedPub
>
0
{
//ethutil.Config.Log.Debugf("Pubkey %x found more then once. Already connected to client.", p.pubkey)
p
.
Stop
()
return
}
if
c
.
Get
(
0
)
.
Uint
()
!=
ProtocolVersion
{
if
c
.
Get
(
0
)
.
Uint
()
!=
ProtocolVersion
{
ethutil
.
Config
.
Log
.
Debugf
(
"Invalid peer version. Require protocol: %d. Received: %d
\n
"
,
ProtocolVersion
,
c
.
Get
(
0
)
.
Uint
())
ethutil
.
Config
.
Log
.
Debugf
(
"Invalid peer version. Require protocol: %d. Received: %d
\n
"
,
ProtocolVersion
,
c
.
Get
(
0
)
.
Uint
())
p
.
Stop
()
p
.
Stop
()
...
@@ -625,7 +651,6 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -625,7 +651,6 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
// If this is an inbound connection send an ack back
// If this is an inbound connection send an ack back
if
p
.
inbound
{
if
p
.
inbound
{
p
.
pubkey
=
c
.
Get
(
5
)
.
Bytes
()
p
.
port
=
uint16
(
c
.
Get
(
4
)
.
Uint
())
p
.
port
=
uint16
(
c
.
Get
(
4
)
.
Uint
())
// Self connect detection
// Self connect detection
...
@@ -647,6 +672,11 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -647,6 +672,11 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
p
.
SetVersion
(
c
.
Get
(
2
)
.
Str
())
p
.
SetVersion
(
c
.
Get
(
2
)
.
Str
())
}
}
p
.
ethereum
.
PushPeer
(
p
)
p
.
ethereum
.
reactor
.
Post
(
"peerList"
,
p
.
ethereum
.
Peers
())
ethutil
.
Config
.
Log
.
Infof
(
"[SERV] Added peer (%s) %d / %d
\n
"
,
p
.
conn
.
RemoteAddr
(),
p
.
ethereum
.
Peers
()
.
Len
(),
p
.
ethereum
.
MaxPeers
)
// Catch up with the connected peer
// Catch up with the connected peer
if
!
p
.
ethereum
.
IsUpToDate
()
{
if
!
p
.
ethereum
.
IsUpToDate
()
{
ethutil
.
Config
.
Log
.
Debugln
(
"Already syncing up with a peer; sleeping"
)
ethutil
.
Config
.
Log
.
Debugln
(
"Already syncing up with a peer; sleeping"
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment