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
aa934157
Commit
aa934157
authored
Feb 02, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Disconnection reasons
parent
f4a96ca5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
13 deletions
+38
-13
peer.go
peer.go
+38
-13
No files found.
peer.go
View file @
aa934157
...
...
@@ -17,27 +17,53 @@ const (
outputBufferSize
=
50
)
// Peer capabillities
type
DiscReason
byte
const
(
DiscReRequested
=
0x00
DiscReTcpSysErr
=
0x01
DiscBadProto
=
0x02
DiscBadPeer
=
0x03
DiscTooManyPeers
=
0x04
)
var
discReasonToString
=
[]
string
{
"Disconnect requested"
,
"Disconnect TCP sys error"
,
"Disconnect Bad protocol"
,
"Disconnect Useless peer"
,
"Disconnect Too many peers"
,
}
func
(
d
DiscReason
)
String
()
string
{
if
len
(
discReasonToString
)
>
int
(
d
)
{
return
"Unknown"
}
return
discReasonToString
[
d
]
}
// Peer capabilities
type
Caps
byte
const
(
Cap
Discovery
Ty
=
0x01
Cap
PeerDisc
Ty
=
0x01
CapTxTy
=
0x02
CapChainTy
=
0x04
CapDefault
=
CapChainTy
|
CapTxTy
|
Cap
Discovery
Ty
CapDefault
=
CapChainTy
|
CapTxTy
|
Cap
PeerDisc
Ty
)
var
capsToString
=
map
[
Caps
]
string
{
Cap
Discovery
Ty
:
"Peer discovery"
,
Cap
PeerDisc
Ty
:
"Peer discovery"
,
CapTxTy
:
"Transaction relaying"
,
CapChainTy
:
"Block chain relaying"
,
}
func
(
c
Caps
)
String
()
string
{
var
caps
[]
string
if
c
&
Cap
Discovery
Ty
>
0
{
caps
=
append
(
caps
,
capsToString
[
Cap
Discovery
Ty
])
if
c
&
Cap
PeerDisc
Ty
>
0
{
caps
=
append
(
caps
,
capsToString
[
Cap
PeerDisc
Ty
])
}
if
c
&
CapChainTy
>
0
{
caps
=
append
(
caps
,
capsToString
[
CapChainTy
])
...
...
@@ -175,7 +201,7 @@ out:
// Service timer takes care of peer broadcasting, transaction
// posting or block posting
case
<-
serviceTimer
.
C
:
if
p
.
caps
&
Cap
Discovery
Ty
>
0
{
if
p
.
caps
&
Cap
PeerDisc
Ty
>
0
{
msg
:=
p
.
peersMessage
()
p
.
ethereum
.
BroadcastMsg
(
msg
)
}
...
...
@@ -220,6 +246,7 @@ out:
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgGetPeersTy
,
""
))
case
ethwire
.
MsgDiscTy
:
p
.
Stop
()
log
.
Println
(
"Disconnect peer:"
,
DiscReason
(
msg
.
Data
.
Get
(
0
)
.
AsUint
()))
case
ethwire
.
MsgPingTy
:
// Respond back with pong
p
.
QueueMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgPongTy
,
""
))
...
...
@@ -381,8 +408,6 @@ func (p *Peer) Stop() {
p
.
writeMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgDiscTy
,
""
))
p
.
conn
.
Close
()
}
log
.
Println
(
"Peer shutdown"
)
}
func
(
p
*
Peer
)
pushHandshake
()
error
{
...
...
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