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
7f100e96
Commit
7f100e96
authored
Jan 30, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Self connect detect
parent
7ccf51fd
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
43 additions
and
13 deletions
+43
-13
ethereum.go
ethereum.go
+1
-1
peer.go
peer.go
+42
-12
No files found.
ethereum.go
View file @
7f100e96
...
@@ -72,7 +72,7 @@ func (s *Ethereum) AddPeer(conn net.Conn) {
...
@@ -72,7 +72,7 @@ func (s *Ethereum) AddPeer(conn net.Conn) {
peer
:=
NewPeer
(
conn
,
s
,
true
)
peer
:=
NewPeer
(
conn
,
s
,
true
)
if
peer
!=
nil
{
if
peer
!=
nil
{
if
s
.
peers
.
Len
()
>
-
1
{
if
s
.
peers
.
Len
()
>
25
{
log
.
Println
(
"SEED"
)
log
.
Println
(
"SEED"
)
peer
.
Start
(
true
)
peer
.
Start
(
true
)
}
else
{
}
else
{
...
...
peer.go
View file @
7f100e96
...
@@ -178,6 +178,8 @@ out:
...
@@ -178,6 +178,8 @@ out:
case
ethwire
.
MsgHandshakeTy
:
case
ethwire
.
MsgHandshakeTy
:
// Version message
// Version message
p
.
handleHandshake
(
msg
)
p
.
handleHandshake
(
msg
)
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetPeersTy
,
""
))
case
ethwire
.
MsgDiscTy
:
case
ethwire
.
MsgDiscTy
:
p
.
Stop
()
p
.
Stop
()
case
ethwire
.
MsgPingTy
:
case
ethwire
.
MsgPingTy
:
...
@@ -216,12 +218,12 @@ out:
...
@@ -216,12 +218,12 @@ out:
// Received a list of peers (probably because MsgGetPeersTy was send)
// Received a list of peers (probably because MsgGetPeersTy was send)
// Only act on message if we actually requested for a peers list
// Only act on message if we actually requested for a peers list
if
p
.
requestedPeerList
{
if
p
.
requestedPeerList
{
data
:=
ethutil
.
Conv
(
msg
.
Data
)
data
:=
msg
.
Data
// Create new list of possible peers for the ethereum to process
// Create new list of possible peers for the ethereum to process
peers
:=
make
([]
string
,
data
.
Length
())
peers
:=
make
([]
string
,
data
.
Length
())
// Parse each possible peer
// Parse each possible peer
for
i
:=
0
;
i
<
data
.
Length
();
i
++
{
for
i
:=
0
;
i
<
data
.
Length
();
i
++
{
peers
[
i
]
=
data
.
Get
(
i
)
.
AsString
()
+
strconv
.
Itoa
(
int
(
data
.
Get
(
i
)
.
AsUint
()))
peers
[
i
]
=
data
.
Get
(
i
)
.
Get
(
0
)
.
AsString
()
+
":"
+
strconv
.
Itoa
(
int
(
data
.
Get
(
i
)
.
Get
(
1
)
.
AsUint
()))
}
}
// Connect to the list of peers
// Connect to the list of peers
...
@@ -278,14 +280,27 @@ out:
...
@@ -278,14 +280,27 @@ out:
func
(
p
*
Peer
)
Start
(
seed
bool
)
{
func
(
p
*
Peer
)
Start
(
seed
bool
)
{
p
.
seed
=
seed
p
.
seed
=
seed
if
!
p
.
inbound
{
peerHost
,
_
,
_
:=
net
.
SplitHostPort
(
p
.
conn
.
LocalAddr
()
.
String
())
servHost
,
_
,
_
:=
net
.
SplitHostPort
(
p
.
conn
.
RemoteAddr
()
.
String
())
log
.
Println
(
peerHost
,
servHost
)
if
peerHost
==
servHost
{
log
.
Println
(
"Connected to self"
)
p
.
Stop
()
return
}
//if !p.inbound {
err
:=
p
.
pushHandshake
()
err
:=
p
.
pushHandshake
()
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Printf
(
"Peer can't send outbound version ack"
,
err
)
log
.
Printf
(
"Peer can't send outbound version ack"
,
err
)
p
.
Stop
()
p
.
Stop
()
return
}
}
}
//
}
// Run the outbound handler in a new goroutine
// Run the outbound handler in a new goroutine
go
p
.
HandleOutbound
()
go
p
.
HandleOutbound
()
...
@@ -320,11 +335,10 @@ func (p *Peer) pushHandshake() error {
...
@@ -320,11 +335,10 @@ func (p *Peer) pushHandshake() error {
// Pushes the list of outbound peers to the client when requested
// Pushes the list of outbound peers to the client when requested
func
(
p
*
Peer
)
pushPeers
()
{
func
(
p
*
Peer
)
pushPeers
()
{
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
OutboundPeers
()))
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
OutboundPeers
()))
// Serialise each peer
// Serialise each peer
for
i
,
peer
:=
range
p
.
ethereum
.
OutboundPeers
()
{
for
i
,
peer
:=
range
p
.
ethereum
.
OutboundPeers
()
{
outPeers
[
i
]
=
peer
.
Rlp
Encode
()
outPeers
[
i
]
=
peer
.
Rlp
Data
()
}
}
// Send message to the peer with the known list of connected clients
// Send message to the peer with the known list of connected clients
...
@@ -351,8 +365,8 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -351,8 +365,8 @@ 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
)})
//
msg := ethwire.NewMessage(ethwire.MsgGetChainTy, []interface{}{p.ethereum.BlockManager.BlockChain().CurrentBlock.Hash(), uint64(100)})
p
.
QueueMessage
(
msg
)
//
p.QueueMessage(msg)
istr
=
"outbound"
istr
=
"outbound"
}
}
...
@@ -360,6 +374,22 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -360,6 +374,22 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
log
.
Printf
(
"peer connect (%s) %v %s
\n
"
,
istr
,
p
.
conn
.
RemoteAddr
(),
c
.
Get
(
2
)
.
AsString
())
log
.
Printf
(
"peer connect (%s) %v %s
\n
"
,
istr
,
p
.
conn
.
RemoteAddr
(),
c
.
Get
(
2
)
.
AsString
())
}
}
func
(
p
*
Peer
)
RlpData
()
[]
interface
{}
{
host
,
prt
,
err
:=
net
.
SplitHostPort
(
p
.
conn
.
RemoteAddr
()
.
String
())
if
err
!=
nil
{
return
nil
}
port
,
err
:=
strconv
.
Atoi
(
prt
)
if
err
!=
nil
{
return
nil
}
//port := ethutil.NumberToBytes(uint16(i), 16)
return
[]
interface
{}{
host
,
port
}
}
func
(
p
*
Peer
)
RlpEncode
()
[]
byte
{
func
(
p
*
Peer
)
RlpEncode
()
[]
byte
{
host
,
prt
,
err
:=
net
.
SplitHostPort
(
p
.
conn
.
RemoteAddr
()
.
String
())
host
,
prt
,
err
:=
net
.
SplitHostPort
(
p
.
conn
.
RemoteAddr
()
.
String
())
if
err
!=
nil
{
if
err
!=
nil
{
...
...
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