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
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
3c4fb01d
Commit
3c4fb01d
authored
11 years ago
by
Jeffrey Wilcke
Browse files
Options
Downloads
Patches
Plain Diff
Version 3 and added added catch up
parent
c00b1dd5
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
peer.go
+28
-7
28 additions, 7 deletions
peer.go
with
28 additions
and
7 deletions
peer.go
+
28
−
7
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
}
}
}
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