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
3c4fb01d
Commit
3c4fb01d
authored
Feb 10, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Version 3 and added added catch up
parent
c00b1dd5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
7 deletions
+28
-7
peer.go
peer.go
+28
-7
No files found.
peer.go
View file @
3c4fb01d
...
@@ -112,6 +112,9 @@ type Peer struct {
...
@@ -112,6 +112,9 @@ type Peer struct {
caps
Caps
caps
Caps
pubkey
[]
byte
pubkey
[]
byte
// Indicated whether the node is catching up or not
catchingUp
bool
}
}
func
NewPeer
(
conn
net
.
Conn
,
ethereum
*
Ethereum
,
inbound
bool
)
*
Peer
{
func
NewPeer
(
conn
net
.
Conn
,
ethereum
*
Ethereum
,
inbound
bool
)
*
Peer
{
...
@@ -240,6 +243,9 @@ func (p *Peer) HandleInbound() {
...
@@ -240,6 +243,9 @@ func (p *Peer) HandleInbound() {
out
:
out
:
for
atomic
.
LoadInt32
(
&
p
.
disconnect
)
==
0
{
for
atomic
.
LoadInt32
(
&
p
.
disconnect
)
==
0
{
// HMM?
time
.
Sleep
(
500
*
time
.
Millisecond
)
// Wait for a message from the peer
// Wait for a message from the peer
msgs
,
err
:=
ethwire
.
ReadMessages
(
p
.
conn
)
msgs
,
err
:=
ethwire
.
ReadMessages
(
p
.
conn
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -277,6 +283,11 @@ out:
...
@@ -277,6 +283,11 @@ out:
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Println
(
err
)
log
.
Println
(
err
)
}
else
{
if
p
.
catchingUp
&&
msg
.
Data
.
Length
()
>
1
{
p
.
catchingUp
=
false
p
.
CatchupWithPeer
()
}
}
}
}
}
case
ethwire
.
MsgTxTy
:
case
ethwire
.
MsgTxTy
:
...
@@ -419,7 +430,7 @@ func (p *Peer) Stop() {
...
@@ -419,7 +430,7 @@ func (p *Peer) Stop() {
func
(
p
*
Peer
)
pushHandshake
()
error
{
func
(
p
*
Peer
)
pushHandshake
()
error
{
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgHandshakeTy
,
[]
interface
{}{
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgHandshakeTy
,
[]
interface
{}{
uint32
(
2
),
uint32
(
0
),
"/Ethereum(G) v0.0.1/"
,
p
.
pubkey
,
byte
(
p
.
caps
),
p
.
port
,
uint32
(
3
),
uint32
(
0
),
"/Ethereum(G) v0.0.1/"
,
byte
(
p
.
caps
),
p
.
port
,
p
.
pubkey
,
})
})
p
.
QueueMessage
(
msg
)
p
.
QueueMessage
(
msg
)
...
@@ -452,15 +463,16 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -452,15 +463,16 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
return
return
}
}
// [PROTOCOL_VERSION, NETWORK_ID, CLIENT_ID]
// [PROTOCOL_VERSION, NETWORK_ID, CLIENT_ID
, CAPS, PORT, PUBKEY
]
p
.
versionKnown
=
true
p
.
versionKnown
=
true
var
istr
string
var
istr
string
// 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
(
3
)
.
AsBytes
()
p
.
pubkey
=
c
.
Get
(
5
)
.
AsBytes
()
p
.
port
=
uint16
(
c
.
Get
(
5
)
.
AsUint
())
p
.
port
=
uint16
(
c
.
Get
(
4
)
.
AsUint
())
// Self connect detection
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
data
,
_
:=
ethutil
.
Config
.
Db
.
Get
([]
byte
(
"KeyRing"
))
pubkey
:=
ethutil
.
NewValueFromBytes
(
data
)
.
Get
(
2
)
.
Bytes
()
pubkey
:=
ethutil
.
NewValueFromBytes
(
data
)
.
Get
(
2
)
.
Bytes
()
if
bytes
.
Compare
(
pubkey
,
p
.
pubkey
)
==
0
{
if
bytes
.
Compare
(
pubkey
,
p
.
pubkey
)
==
0
{
...
@@ -471,17 +483,26 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -471,17 +483,26 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
istr
=
"inbound"
istr
=
"inbound"
}
else
{
}
else
{
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgGetChainTy
,
[]
interface
{}{
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
uint64
(
100
)})
p
.
CatchupWithPeer
()
p
.
QueueMessage
(
msg
)
istr
=
"outbound"
istr
=
"outbound"
}
}
p
.
caps
=
Caps
(
c
.
Get
(
4
)
.
AsByte
())
p
.
caps
=
Caps
(
c
.
Get
(
3
)
.
AsByte
())
log
.
Printf
(
"peer connect (%s) %v %s [%s]
\n
"
,
istr
,
p
.
conn
.
RemoteAddr
(),
c
.
Get
(
2
)
.
AsString
(),
p
.
caps
)
log
.
Printf
(
"peer connect (%s) %v %s [%s]
\n
"
,
istr
,
p
.
conn
.
RemoteAddr
(),
c
.
Get
(
2
)
.
AsString
(),
p
.
caps
)
}
}
func
(
p
*
Peer
)
CatchupWithPeer
()
{
if
!
p
.
catchingUp
{
p
.
catchingUp
=
true
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgGetChainTy
,
[]
interface
{}{
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
(),
uint64
(
50
)})
p
.
QueueMessage
(
msg
)
log
.
Printf
(
"Requesting blockchain up from %x
\n
"
,
p
.
ethereum
.
BlockManager
.
BlockChain
()
.
CurrentBlock
.
Hash
())
}
}
func
(
p
*
Peer
)
RlpData
()
[]
interface
{}
{
func
(
p
*
Peer
)
RlpData
()
[]
interface
{}
{
return
[]
interface
{}{
p
.
host
,
p
.
port
,
p
.
pubkey
}
return
[]
interface
{}{
p
.
host
,
p
.
port
,
p
.
pubkey
}
}
}
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