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
fb6ff617
Commit
fb6ff617
authored
Jun 02, 2014
by
Maran
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implemented Public Peer interface
parent
ff8a834c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
91 additions
and
6 deletions
+91
-6
state_manager.go
ethchain/state_manager.go
+12
-0
pub.go
ethpub/pub.go
+13
-0
types.go
ethpub/types.go
+29
-1
peer.go
peer.go
+37
-5
No files found.
ethchain/state_manager.go
View file @
fb6ff617
...
@@ -2,6 +2,7 @@ package ethchain
...
@@ -2,6 +2,7 @@ package ethchain
import
(
import
(
"bytes"
"bytes"
"container/list"
"fmt"
"fmt"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/eth-go/ethwire"
...
@@ -14,6 +15,16 @@ type BlockProcessor interface {
...
@@ -14,6 +15,16 @@ type BlockProcessor interface {
ProcessBlock
(
block
*
Block
)
ProcessBlock
(
block
*
Block
)
}
}
type
Peer
interface
{
Inbound
()
bool
LastSend
()
time
.
Time
LastPong
()
int64
Host
()
[]
byte
Port
()
uint16
Version
()
string
Connected
()
*
int32
}
type
EthManager
interface
{
type
EthManager
interface
{
StateManager
()
*
StateManager
StateManager
()
*
StateManager
BlockChain
()
*
BlockChain
BlockChain
()
*
BlockChain
...
@@ -23,6 +34,7 @@ type EthManager interface {
...
@@ -23,6 +34,7 @@ type EthManager interface {
PeerCount
()
int
PeerCount
()
int
IsMining
()
bool
IsMining
()
bool
IsListening
()
bool
IsListening
()
bool
Peers
()
*
list
.
List
}
}
type
StateManager
struct
{
type
StateManager
struct
{
...
...
ethpub/pub.go
View file @
fb6ff617
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"math/big"
"math/big"
"strings"
"strings"
"sync/atomic"
)
)
type
PEthereum
struct
{
type
PEthereum
struct
{
...
@@ -51,6 +52,18 @@ func (lib *PEthereum) GetPeerCount() int {
...
@@ -51,6 +52,18 @@ func (lib *PEthereum) GetPeerCount() int {
return
lib
.
manager
.
PeerCount
()
return
lib
.
manager
.
PeerCount
()
}
}
func
(
lib
*
PEthereum
)
GetPeers
()
[]
PPeer
{
var
peers
[]
PPeer
for
peer
:=
lib
.
manager
.
Peers
()
.
Front
();
peer
!=
nil
;
peer
=
peer
.
Next
()
{
p
:=
peer
.
Value
.
(
ethchain
.
Peer
)
if
atomic
.
LoadInt32
(
p
.
Connected
())
!=
0
{
peers
=
append
(
peers
,
*
NewPPeer
(
p
))
}
}
return
peers
}
func
(
lib
*
PEthereum
)
GetIsMining
()
bool
{
func
(
lib
*
PEthereum
)
GetIsMining
()
bool
{
return
lib
.
manager
.
IsMining
()
return
lib
.
manager
.
IsMining
()
}
}
...
...
ethpub/types.go
View file @
fb6ff617
...
@@ -3,12 +3,40 @@ package ethpub
...
@@ -3,12 +3,40 @@ package ethpub
import
(
import
(
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"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"
_
"log"
"strings"
"strings"
)
)
// Peer interface exposed to QML
type
PPeer
struct
{
ref
*
ethchain
.
Peer
Inbound
bool
`json:"isInbound"`
LastSend
int64
`json:"lastSend"`
LastPong
int64
`json:"lastPong"`
Ip
string
`json:"ip"`
Port
int
`json:"port"`
Version
string
`json:"version"`
LastResponse
string
`json:"lastResponse"`
}
func
NewPPeer
(
peer
ethchain
.
Peer
)
*
PPeer
{
if
peer
==
nil
{
return
nil
}
// TODO: There must be something build in to do this?
var
ip
[]
string
for
_
,
i
:=
range
peer
.
Host
()
{
ip
=
append
(
ip
,
fmt
.
Sprintf
(
"%d"
,
i
))
}
ipAddress
:=
strings
.
Join
(
ip
,
"."
)
return
&
PPeer
{
ref
:
&
peer
,
Inbound
:
peer
.
Inbound
(),
LastSend
:
peer
.
LastSend
()
.
Unix
(),
LastPong
:
peer
.
LastPong
(),
Version
:
peer
.
Version
(),
Ip
:
ipAddress
,
Port
:
int
(
peer
.
Port
())}
}
// Block interface exposed to QML
// Block interface exposed to QML
type
PBlock
struct
{
type
PBlock
struct
{
ref
*
ethchain
.
Block
ref
*
ethchain
.
Block
...
...
peer.go
View file @
fb6ff617
...
@@ -129,7 +129,7 @@ type Peer struct {
...
@@ -129,7 +129,7 @@ type Peer struct {
diverted
bool
diverted
bool
blocksRequested
int
blocksRequested
int
V
ersion
string
v
ersion
string
}
}
func
NewPeer
(
conn
net
.
Conn
,
ethereum
*
Ethereum
,
inbound
bool
)
*
Peer
{
func
NewPeer
(
conn
net
.
Conn
,
ethereum
*
Ethereum
,
inbound
bool
)
*
Peer
{
...
@@ -160,7 +160,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
...
@@ -160,7 +160,7 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
connected
:
0
,
connected
:
0
,
disconnect
:
0
,
disconnect
:
0
,
caps
:
caps
,
caps
:
caps
,
V
ersion
:
ethutil
.
Config
.
ClientString
,
v
ersion
:
ethutil
.
Config
.
ClientString
,
}
}
// 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
...
@@ -184,6 +184,34 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
...
@@ -184,6 +184,34 @@ func NewOutboundPeer(addr string, ethereum *Ethereum, caps Caps) *Peer {
return
p
return
p
}
}
// Getters
func
(
p
*
Peer
)
Inbound
()
bool
{
return
p
.
inbound
}
func
(
p
*
Peer
)
LastSend
()
time
.
Time
{
return
p
.
lastSend
}
func
(
p
*
Peer
)
LastPong
()
int64
{
return
p
.
lastPong
}
func
(
p
*
Peer
)
Host
()
[]
byte
{
return
p
.
host
}
func
(
p
*
Peer
)
Port
()
uint16
{
return
p
.
port
}
func
(
p
*
Peer
)
Version
()
string
{
return
p
.
version
}
func
(
p
*
Peer
)
Connected
()
*
int32
{
return
&
p
.
connected
}
// Setters
func
(
p
*
Peer
)
SetVersion
(
version
string
)
{
p
.
version
=
version
}
// Outputs any RLP encoded data to the peer
// Outputs any RLP encoded data to the peer
func
(
p
*
Peer
)
QueueMessage
(
msg
*
ethwire
.
Msg
)
{
func
(
p
*
Peer
)
QueueMessage
(
msg
*
ethwire
.
Msg
)
{
if
atomic
.
LoadInt32
(
&
p
.
connected
)
!=
1
{
if
atomic
.
LoadInt32
(
&
p
.
connected
)
!=
1
{
...
@@ -531,7 +559,7 @@ func (p *Peer) pushHandshake() error {
...
@@ -531,7 +559,7 @@ func (p *Peer) pushHandshake() error {
pubkey
:=
keyRing
.
PublicKey
pubkey
:=
keyRing
.
PublicKey
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgHandshakeTy
,
[]
interface
{}{
msg
:=
ethwire
.
NewMessage
(
ethwire
.
MsgHandshakeTy
,
[]
interface
{}{
uint32
(
ProtocolVersion
),
uint32
(
0
),
p
.
V
ersion
,
byte
(
p
.
caps
),
p
.
port
,
pubkey
[
1
:
],
uint32
(
ProtocolVersion
),
uint32
(
0
),
p
.
v
ersion
,
byte
(
p
.
caps
),
p
.
port
,
pubkey
[
1
:
],
})
})
p
.
QueueMessage
(
msg
)
p
.
QueueMessage
(
msg
)
...
@@ -588,8 +616,12 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -588,8 +616,12 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
// Set the peer's caps
// Set the peer's caps
p
.
caps
=
Caps
(
c
.
Get
(
3
)
.
Byte
())
p
.
caps
=
Caps
(
c
.
Get
(
3
)
.
Byte
())
// Get a reference to the peers version
// Get a reference to the peers version
p
.
Version
=
c
.
Get
(
2
)
.
Str
()
versionString
:=
c
.
Get
(
2
)
.
Str
()
if
len
(
versionString
)
>
0
{
p
.
SetVersion
(
c
.
Get
(
2
)
.
Str
())
}
// Catch up with the connected peer
// Catch up with the connected peer
if
!
p
.
ethereum
.
IsUpToDate
()
{
if
!
p
.
ethereum
.
IsUpToDate
()
{
...
@@ -615,7 +647,7 @@ func (p *Peer) String() string {
...
@@ -615,7 +647,7 @@ func (p *Peer) String() string {
strConnectType
=
"disconnected"
strConnectType
=
"disconnected"
}
}
return
fmt
.
Sprintf
(
"[%s] (%s) %v %s [%s]"
,
strConnectType
,
strBoundType
,
p
.
conn
.
RemoteAddr
(),
p
.
V
ersion
,
p
.
caps
)
return
fmt
.
Sprintf
(
"[%s] (%s) %v %s [%s]"
,
strConnectType
,
strBoundType
,
p
.
conn
.
RemoteAddr
(),
p
.
v
ersion
,
p
.
caps
)
}
}
func
(
p
*
Peer
)
SyncWithPeerToLastKnown
()
{
func
(
p
*
Peer
)
SyncWithPeerToLastKnown
()
{
...
...
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