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
485e04d9
Commit
485e04d9
authored
May 13, 2014
by
obscuren
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release/poc5-rc4'
parents
a32dffb0
86d6aba0
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
113 additions
and
36 deletions
+113
-36
README.md
README.md
+1
-1
ethereum.go
ethereum.go
+69
-9
pub.go
ethpub/pub.go
+6
-4
server.go
ethrpc/server.go
+6
-4
config.go
ethutil/config.go
+1
-1
peer.go
peer.go
+30
-17
No files found.
README.md
View file @
485e04d9
...
@@ -6,7 +6,7 @@ Ethereum
...
@@ -6,7 +6,7 @@ Ethereum
Ethereum Go Development package (C) Jeffrey Wilcke
Ethereum Go Development package (C) Jeffrey Wilcke
Ethereum is currently in its testing phase. The current state is "Proof
Ethereum is currently in its testing phase. The current state is "Proof
of Concept 5.0 RC
3
". For build instructions see the
[
Wiki
](
https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go
)
).
of Concept 5.0 RC
4
". For build instructions see the
[
Wiki
](
https://github.com/ethereum/go-ethereum/wiki/Building-Ethereum(Go
)
).
Ethereum Go is split up in several sub packages Please refer to each
Ethereum Go is split up in several sub packages Please refer to each
individual package for more information.
individual package for more information.
...
...
ethereum.go
View file @
485e04d9
...
@@ -2,6 +2,7 @@ package eth
...
@@ -2,6 +2,7 @@ package eth
import
(
import
(
"container/list"
"container/list"
"fmt"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethchain"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethdb"
"github.com/ethereum/eth-go/ethrpc"
"github.com/ethereum/eth-go/ethrpc"
...
@@ -9,9 +10,11 @@ import (
...
@@ -9,9 +10,11 @@ import (
"github.com/ethereum/eth-go/ethwire"
"github.com/ethereum/eth-go/ethwire"
"io/ioutil"
"io/ioutil"
"log"
"log"
"math/rand"
"net"
"net"
"net/http"
"net/http"
"strconv"
"strconv"
"strings"
"sync"
"sync"
"sync/atomic"
"sync/atomic"
"time"
"time"
...
@@ -122,12 +125,20 @@ func (s *Ethereum) TxPool() *ethchain.TxPool {
...
@@ -122,12 +125,20 @@ func (s *Ethereum) TxPool() *ethchain.TxPool {
return
s
.
txPool
return
s
.
txPool
}
}
func
(
s
*
Ethereum
)
ServerCaps
()
Caps
{
return
s
.
serverCaps
}
func
(
s
*
Ethereum
)
AddPeer
(
conn
net
.
Conn
)
{
func
(
s
*
Ethereum
)
AddPeer
(
conn
net
.
Conn
)
{
peer
:=
NewPeer
(
conn
,
s
,
true
)
peer
:=
NewPeer
(
conn
,
s
,
true
)
if
peer
!=
nil
&&
s
.
peers
.
Len
()
<
s
.
MaxPeers
{
if
peer
!=
nil
{
if
s
.
peers
.
Len
()
<
s
.
MaxPeers
{
s
.
peers
.
PushBack
(
peer
)
s
.
peers
.
PushBack
(
peer
)
peer
.
Start
()
peer
.
Start
()
}
else
{
ethutil
.
Config
.
Log
.
Debugf
(
"[SERV] Max connected peers reached. Not adding incoming peer."
)
}
}
}
}
}
...
@@ -142,15 +153,51 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
...
@@ -142,15 +153,51 @@ func (s *Ethereum) ConnectToPeer(addr string) error {
if
s
.
peers
.
Len
()
<
s
.
MaxPeers
{
if
s
.
peers
.
Len
()
<
s
.
MaxPeers
{
var
alreadyConnected
bool
var
alreadyConnected
bool
ahost
,
_
,
_
:=
net
.
SplitHostPort
(
addr
)
var
chost
string
ips
,
err
:=
net
.
LookupIP
(
ahost
)
if
err
!=
nil
{
return
err
}
else
{
// If more then one ip is available try stripping away the ipv6 ones
if
len
(
ips
)
>
1
{
var
ipsv4
[]
net
.
IP
// For now remove the ipv6 addresses
for
_
,
ip
:=
range
ips
{
if
strings
.
Contains
(
ip
.
String
(),
"::"
)
{
continue
}
else
{
ipsv4
=
append
(
ipsv4
,
ip
)
}
}
if
len
(
ipsv4
)
==
0
{
return
fmt
.
Errorf
(
"[SERV] No IPV4 addresses available for hostname"
)
}
// Pick a random ipv4 address, simulating round-robin DNS.
rand
.
Seed
(
time
.
Now
()
.
UTC
()
.
UnixNano
())
i
:=
rand
.
Intn
(
len
(
ipsv4
))
chost
=
ipsv4
[
i
]
.
String
()
}
else
{
if
len
(
ips
)
==
0
{
return
fmt
.
Errorf
(
"[SERV] No IPs resolved for the given hostname"
)
return
nil
}
chost
=
ips
[
0
]
.
String
()
}
}
eachPeer
(
s
.
peers
,
func
(
p
*
Peer
,
v
*
list
.
Element
)
{
eachPeer
(
s
.
peers
,
func
(
p
*
Peer
,
v
*
list
.
Element
)
{
if
p
.
conn
==
nil
{
if
p
.
conn
==
nil
{
return
return
}
}
phost
,
_
,
_
:=
net
.
SplitHostPort
(
p
.
conn
.
RemoteAddr
()
.
String
())
phost
,
_
,
_
:=
net
.
SplitHostPort
(
p
.
conn
.
RemoteAddr
()
.
String
())
ahost
,
_
,
_
:=
net
.
SplitHostPort
(
addr
)
if
phost
==
a
host
{
if
phost
==
c
host
{
alreadyConnected
=
true
alreadyConnected
=
true
ethutil
.
Config
.
Log
.
Debugf
(
"[SERV] Peer %s already added.
\n
"
,
chost
)
return
return
}
}
})
})
...
@@ -278,8 +325,21 @@ func (s *Ethereum) Start(seed bool) {
...
@@ -278,8 +325,21 @@ func (s *Ethereum) Start(seed bool) {
}
}
func
(
s
*
Ethereum
)
Seed
()
{
func
(
s
*
Ethereum
)
Seed
()
{
ethutil
.
Config
.
Log
.
Debugln
(
"Seeding"
)
ethutil
.
Config
.
Log
.
Debugln
(
"[SERV] Retrieving seed nodes"
)
// DNS Bootstrapping
// Eth-Go Bootstrapping
ips
,
er
:=
net
.
LookupIP
(
"seed.bysh.me"
)
if
er
==
nil
{
peers
:=
[]
string
{}
for
_
,
ip
:=
range
ips
{
node
:=
fmt
.
Sprintf
(
"%s:%d"
,
ip
.
String
(),
30303
)
ethutil
.
Config
.
Log
.
Debugln
(
"[SERV] Found DNS Go Peer:"
,
node
)
peers
=
append
(
peers
,
node
)
}
s
.
ProcessPeerList
(
peers
)
}
// Official DNS Bootstrapping
_
,
nodes
,
err
:=
net
.
LookupSRV
(
"eth"
,
"tcp"
,
"ethereum.org"
)
_
,
nodes
,
err
:=
net
.
LookupSRV
(
"eth"
,
"tcp"
,
"ethereum.org"
)
if
err
==
nil
{
if
err
==
nil
{
peers
:=
[]
string
{}
peers
:=
[]
string
{}
...
@@ -293,11 +353,11 @@ func (s *Ethereum) Seed() {
...
@@ -293,11 +353,11 @@ func (s *Ethereum) Seed() {
for
_
,
a
:=
range
addr
{
for
_
,
a
:=
range
addr
{
// Build string out of SRV port and Resolved IP
// Build string out of SRV port and Resolved IP
peer
:=
net
.
JoinHostPort
(
a
,
port
)
peer
:=
net
.
JoinHostPort
(
a
,
port
)
log
.
Println
(
"
Found DNS Bootstrap Peer:"
,
peer
)
ethutil
.
Config
.
Log
.
Debugln
(
"[SERV]
Found DNS Bootstrap Peer:"
,
peer
)
peers
=
append
(
peers
,
peer
)
peers
=
append
(
peers
,
peer
)
}
}
}
else
{
}
else
{
log
.
Println
(
"
Couldn't resolve :"
,
target
)
ethutil
.
Config
.
Log
.
Debugln
(
"[SERV}
Couldn't resolve :"
,
target
)
}
}
}
}
// Connect to Peer list
// Connect to Peer list
...
...
ethpub/pub.go
View file @
485e04d9
...
@@ -6,16 +6,18 @@ import (
...
@@ -6,16 +6,18 @@ import (
)
)
type
PEthereum
struct
{
type
PEthereum
struct
{
manager
ethchain
.
EthManager
stateManager
*
ethchain
.
StateManager
stateManager
*
ethchain
.
StateManager
blockChain
*
ethchain
.
BlockChain
blockChain
*
ethchain
.
BlockChain
txPool
*
ethchain
.
TxPool
txPool
*
ethchain
.
TxPool
}
}
func
NewPEthereum
(
sm
*
ethchain
.
StateManager
,
bc
*
ethchain
.
BlockChain
,
txp
*
ethchain
.
TxPool
)
*
PEthereum
{
func
NewPEthereum
(
manager
ethchain
.
EthManager
)
*
PEthereum
{
return
&
PEthereum
{
return
&
PEthereum
{
sm
,
manager
,
bc
,
manager
.
StateManager
(),
txp
,
manager
.
BlockChain
(),
manager
.
TxPool
(),
}
}
}
}
...
...
ethrpc/server.go
View file @
485e04d9
package
ethrpc
package
ethrpc
import
(
import
(
"fmt"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethpub"
"github.com/ethereum/eth-go/ethutil"
"github.com/ethereum/eth-go/ethutil"
"net"
"net"
...
@@ -48,15 +49,16 @@ func (s *JsonRpcServer) Start() {
...
@@ -48,15 +49,16 @@ func (s *JsonRpcServer) Start() {
}
}
}
}
func
NewJsonRpcServer
(
ethp
*
ethpub
.
PEthereum
)
*
JsonRpcServer
{
func
NewJsonRpcServer
(
ethp
*
ethpub
.
PEthereum
,
port
int
)
(
*
JsonRpcServer
,
error
)
{
l
,
err
:=
net
.
Listen
(
"tcp"
,
":30304"
)
sport
:=
fmt
.
Sprintf
(
":%d"
,
port
)
l
,
err
:=
net
.
Listen
(
"tcp"
,
sport
)
if
err
!=
nil
{
if
err
!=
nil
{
ethutil
.
Config
.
Log
.
Infoln
(
"Error starting JSON-RPC"
)
return
nil
,
err
}
}
return
&
JsonRpcServer
{
return
&
JsonRpcServer
{
listener
:
l
,
listener
:
l
,
quit
:
make
(
chan
bool
),
quit
:
make
(
chan
bool
),
ethp
:
ethp
,
ethp
:
ethp
,
}
}
,
nil
}
}
ethutil/config.go
View file @
485e04d9
...
@@ -50,7 +50,7 @@ func ReadConfig(base string) *config {
...
@@ -50,7 +50,7 @@ func ReadConfig(base string) *config {
}
}
}
}
Config
=
&
config
{
ExecPath
:
path
,
Debug
:
true
,
Ver
:
"0.5.0 RC
3
"
}
Config
=
&
config
{
ExecPath
:
path
,
Debug
:
true
,
Ver
:
"0.5.0 RC
4
"
}
Config
.
Log
=
NewLogger
(
LogFile
|
LogStd
,
LogLevelDebug
)
Config
.
Log
=
NewLogger
(
LogFile
|
LogStd
,
LogLevelDebug
)
Config
.
SetClientString
(
"/Ethereum(G)"
)
Config
.
SetClientString
(
"/Ethereum(G)"
)
}
}
...
...
peer.go
View file @
485e04d9
...
@@ -2,6 +2,7 @@ package eth
...
@@ -2,6 +2,7 @@ package eth
import
(
import
(
"bytes"
"bytes"
"container/list"
"fmt"
"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"
...
@@ -146,6 +147,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
...
@@ -146,6 +147,7 @@ func NewPeer(conn net.Conn, ethereum *Ethereum, inbound bool) *Peer {
port
:
30303
,
port
:
30303
,
pubkey
:
pubkey
,
pubkey
:
pubkey
,
blocksRequested
:
10
,
blocksRequested
:
10
,
caps
:
ethereum
.
ServerCaps
(),
}
}
}
}
...
@@ -400,7 +402,7 @@ func (p *Peer) HandleInbound() {
...
@@ -400,7 +402,7 @@ func (p *Peer) HandleInbound() {
case
ethwire
.
MsgPeersTy
:
case
ethwire
.
MsgPeersTy
:
// 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
:=
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
.
Len
())
peers
:=
make
([]
string
,
data
.
Len
())
...
@@ -415,7 +417,7 @@ func (p *Peer) HandleInbound() {
...
@@ -415,7 +417,7 @@ func (p *Peer) HandleInbound() {
// Mark unrequested again
// Mark unrequested again
p
.
requestedPeerList
=
false
p
.
requestedPeerList
=
false
//
}
}
case
ethwire
.
MsgGetChainTy
:
case
ethwire
.
MsgGetChainTy
:
var
parent
*
ethchain
.
Block
var
parent
*
ethchain
.
Block
// Length minus one since the very last element in the array is a count
// Length minus one since the very last element in the array is a count
...
@@ -514,6 +516,15 @@ func (p *Peer) Stop() {
...
@@ -514,6 +516,15 @@ func (p *Peer) Stop() {
p
.
writeMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgDiscTy
,
""
))
p
.
writeMessage
(
ethwire
.
NewMessage
(
ethwire
.
MsgDiscTy
,
""
))
p
.
conn
.
Close
()
p
.
conn
.
Close
()
}
}
// Pre-emptively remove the peer; don't wait for reaping. We already know it's dead if we are here
p
.
ethereum
.
peerMut
.
Lock
()
defer
p
.
ethereum
.
peerMut
.
Unlock
()
eachPeer
(
p
.
ethereum
.
peers
,
func
(
peer
*
Peer
,
e
*
list
.
Element
)
{
if
peer
==
p
{
p
.
ethereum
.
peers
.
Remove
(
e
)
}
})
}
}
func
(
p
*
Peer
)
pushHandshake
()
error
{
func
(
p
*
Peer
)
pushHandshake
()
error
{
...
@@ -533,8 +544,11 @@ func (p *Peer) peersMessage() *ethwire.Msg {
...
@@ -533,8 +544,11 @@ func (p *Peer) peersMessage() *ethwire.Msg {
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
InOutPeers
()))
outPeers
:=
make
([]
interface
{},
len
(
p
.
ethereum
.
InOutPeers
()))
// Serialise each peer
// Serialise each peer
for
i
,
peer
:=
range
p
.
ethereum
.
InOutPeers
()
{
for
i
,
peer
:=
range
p
.
ethereum
.
InOutPeers
()
{
// Don't return localhost as valid peer
if
!
net
.
ParseIP
(
peer
.
conn
.
RemoteAddr
()
.
String
())
.
IsLoopback
()
{
outPeers
[
i
]
=
peer
.
RlpData
()
outPeers
[
i
]
=
peer
.
RlpData
()
}
}
}
// Return the message to the peer with the known list of connected clients
// Return the message to the peer with the known list of connected clients
return
ethwire
.
NewMessage
(
ethwire
.
MsgPeersTy
,
outPeers
)
return
ethwire
.
NewMessage
(
ethwire
.
MsgPeersTy
,
outPeers
)
...
@@ -549,7 +563,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -549,7 +563,7 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
c
:=
msg
.
Data
c
:=
msg
.
Data
if
c
.
Get
(
0
)
.
Uint
()
!=
ProtocolVersion
{
if
c
.
Get
(
0
)
.
Uint
()
!=
ProtocolVersion
{
ethutil
.
Config
.
Log
.
Debugln
(
"Invalid peer version. Require protocol
v5"
)
ethutil
.
Config
.
Log
.
Debugln
(
"Invalid peer version. Require protocol
:"
,
ProtocolVersion
)
p
.
Stop
()
p
.
Stop
()
return
return
}
}
...
@@ -573,7 +587,6 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
...
@@ -573,7 +587,6 @@ func (p *Peer) handleHandshake(msg *ethwire.Msg) {
}
}
// Catch up with the connected peer
// Catch up with the connected peer
// p.CatchupWithPeer(p.ethereum.BlockChain().CurrentBlock.Hash())
p
.
SyncWithBlocks
()
p
.
SyncWithBlocks
()
// Set the peer's caps
// Set the peer's caps
...
...
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