Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
plugin
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
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
link33
plugin
Commits
defa98e1
Commit
defa98e1
authored
Feb 07, 2021
by
libangzhu
Browse files
Options
Browse Files
Download
Plain Diff
merge conflict
parents
87ad2da4
43d0c91f
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
39 additions
and
32 deletions
+39
-32
common.go
plugin/p2p/gossip/common.go
+6
-4
listener.go
plugin/p2p/gossip/listener.go
+1
-0
net_test.go
plugin/p2p/gossip/net_test.go
+1
-1
netaddress.go
plugin/p2p/gossip/netaddress.go
+8
-7
p2p_test.go
plugin/p2p/gossip/p2p_test.go
+20
-19
p2pcli.go
plugin/p2p/gossip/p2pcli.go
+3
-1
No files found.
plugin/p2p/gossip/common.go
View file @
defa98e1
...
@@ -8,14 +8,15 @@ import (
...
@@ -8,14 +8,15 @@ import (
"bytes"
"bytes"
"encoding/binary"
"encoding/binary"
"encoding/hex"
"encoding/hex"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"math/rand"
"math/rand"
"net"
"net"
"strings"
"strings"
"time"
"time"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
)
// P2pComm p2p communication
// P2pComm p2p communication
...
@@ -78,6 +79,7 @@ func (c Comm) GetLocalAddr() string {
...
@@ -78,6 +79,7 @@ func (c Comm) GetLocalAddr() string {
func
(
c
Comm
)
dialPeerWithAddress
(
addr
*
NetAddress
,
persistent
bool
,
node
*
Node
)
(
*
Peer
,
error
)
{
func
(
c
Comm
)
dialPeerWithAddress
(
addr
*
NetAddress
,
persistent
bool
,
node
*
Node
)
(
*
Peer
,
error
)
{
log
.
Debug
(
"dialPeerWithAddress"
)
log
.
Debug
(
"dialPeerWithAddress"
)
conn
,
err
:=
addr
.
DialTimeout
(
node
.
nodeInfo
.
channelVersion
,
node
.
nodeInfo
.
cliCreds
)
conn
,
err
:=
addr
.
DialTimeout
(
node
.
nodeInfo
.
channelVersion
,
node
.
nodeInfo
.
cliCreds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/p2p/gossip/listener.go
View file @
defa98e1
...
@@ -146,6 +146,7 @@ Retry:
...
@@ -146,6 +146,7 @@ Retry:
opts
=
append
(
opts
,
msgRecvOp
,
msgSendOp
,
grpc
.
KeepaliveEnforcementPolicy
(
kaep
),
keepOp
,
maxStreams
,
StatsOp
)
opts
=
append
(
opts
,
msgRecvOp
,
msgSendOp
,
grpc
.
KeepaliveEnforcementPolicy
(
kaep
),
keepOp
,
maxStreams
,
StatsOp
)
if
node
.
nodeInfo
.
servCreds
!=
nil
{
if
node
.
nodeInfo
.
servCreds
!=
nil
{
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
nodeInfo
.
servCreds
))
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
nodeInfo
.
servCreds
))
}
}
dl
.
server
=
grpc
.
NewServer
(
opts
...
)
dl
.
server
=
grpc
.
NewServer
(
opts
...
)
dl
.
p2pserver
=
pServer
dl
.
p2pserver
=
pServer
...
...
plugin/p2p/gossip/net_test.go
View file @
defa98e1
...
@@ -28,7 +28,7 @@ func TestNetAddress(t *testing.T) {
...
@@ -28,7 +28,7 @@ func TestNetAddress(t *testing.T) {
}
}
func
TestAddrRouteble
(
t
*
testing
.
T
)
{
func
TestAddrRouteble
(
t
*
testing
.
T
)
{
resp
:=
P2pComm
.
AddrRouteble
([]
string
{
"114.55.101.159:13802"
},
utils
.
CalcChannelVersion
(
119
,
VERSION
),
nil
)
resp
:=
P2pComm
.
AddrRouteble
([]
string
{
"114.55.101.159:13802"
},
utils
.
CalcChannelVersion
(
119
,
VERSION
),
nil
)
t
.
Log
(
resp
)
t
.
Log
(
resp
)
}
}
...
...
plugin/p2p/gossip/netaddress.go
View file @
defa98e1
...
@@ -7,11 +7,12 @@ package gossip
...
@@ -7,11 +7,12 @@ package gossip
import
(
import
(
"context"
"context"
"fmt"
"fmt"
"google.golang.org/grpc/credentials"
"net"
"net"
"strconv"
"strconv"
"time"
"time"
"google.golang.org/grpc/credentials"
pb
"github.com/33cn/chain33/types"
pb
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/codes"
...
@@ -142,7 +143,7 @@ func isCompressSupport(err error) bool {
...
@@ -142,7 +143,7 @@ func isCompressSupport(err error) bool {
}
}
// DialTimeout dial timeout
// DialTimeout dial timeout
func
(
na
*
NetAddress
)
DialTimeout
(
version
int32
,
creds
credentials
.
TransportCredentials
)
(
*
grpc
.
ClientConn
,
error
)
{
func
(
na
*
NetAddress
)
DialTimeout
(
version
int32
,
creds
credentials
.
TransportCredentials
)
(
*
grpc
.
ClientConn
,
error
)
{
ch
:=
make
(
chan
grpc
.
ServiceConfig
,
1
)
ch
:=
make
(
chan
grpc
.
ServiceConfig
,
1
)
ch
<-
P2pComm
.
GrpcConfig
()
ch
<-
P2pComm
.
GrpcConfig
()
...
@@ -156,16 +157,16 @@ func (na *NetAddress) DialTimeout(version int32,creds credentials.TransportCrede
...
@@ -156,16 +157,16 @@ func (na *NetAddress) DialTimeout(version int32,creds credentials.TransportCrede
maxMsgSize
:=
pb
.
MaxBlockSize
+
1024
*
1024
maxMsgSize
:=
pb
.
MaxBlockSize
+
1024
*
1024
//配置SSL连接
//配置SSL连接
var
secOpt
grpc
.
DialOption
var
secOpt
grpc
.
DialOption
if
creds
==
nil
{
if
creds
==
nil
{
secOpt
=
grpc
.
WithInsecure
()
secOpt
=
grpc
.
WithInsecure
()
}
else
{
}
else
{
secOpt
=
grpc
.
WithTransportCredentials
(
creds
)
secOpt
=
grpc
.
WithTransportCredentials
(
creds
)
}
}
conn
,
err
:=
grpc
.
Dial
(
na
.
String
(),
conn
,
err
:=
grpc
.
Dial
(
na
.
String
(),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallRecvMsgSize
(
maxMsgSize
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallRecvMsgSize
(
maxMsgSize
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallSendMsgSize
(
maxMsgSize
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallSendMsgSize
(
maxMsgSize
)),
grpc
.
WithServiceConfig
(
ch
),
keepaliveOp
,
timeoutOp
,
secOpt
)
grpc
.
WithServiceConfig
(
ch
),
keepaliveOp
,
timeoutOp
,
secOpt
)
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Debug
(
"grpc DialCon"
,
"did not connect"
,
err
,
"addr"
,
na
.
String
())
log
.
Debug
(
"grpc DialCon"
,
"did not connect"
,
err
,
"addr"
,
na
.
String
())
return
nil
,
err
return
nil
,
err
...
...
plugin/p2p/gossip/p2p_test.go
View file @
defa98e1
...
@@ -6,12 +6,13 @@ import (
...
@@ -6,12 +6,13 @@ import (
"encoding/hex"
"encoding/hex"
"encoding/json"
"encoding/json"
"fmt"
"fmt"
"google.golang.org/grpc/credentials"
"net"
"net"
"sort"
"sort"
"sync/atomic"
"sync/atomic"
"time"
"time"
"google.golang.org/grpc/credentials"
"github.com/33cn/chain33/p2p"
"github.com/33cn/chain33/p2p"
"github.com/33cn/chain33/p2p/utils"
"github.com/33cn/chain33/p2p/utils"
...
@@ -367,7 +368,7 @@ func testGrpcStreamConns(t *testing.T, p2p *P2p) {
...
@@ -367,7 +368,7 @@ func testGrpcStreamConns(t *testing.T, p2p *P2p) {
func
testP2pComm
(
t
*
testing
.
T
,
p2p
*
P2p
)
{
func
testP2pComm
(
t
*
testing
.
T
,
p2p
*
P2p
)
{
addrs
:=
P2pComm
.
AddrRouteble
([]
string
{
"localhost:53802"
},
utils
.
CalcChannelVersion
(
testChannel
,
VERSION
),
nil
)
addrs
:=
P2pComm
.
AddrRouteble
([]
string
{
"localhost:53802"
},
utils
.
CalcChannelVersion
(
testChannel
,
VERSION
),
nil
)
t
.
Log
(
addrs
)
t
.
Log
(
addrs
)
i32
:=
P2pComm
.
BytesToInt32
([]
byte
{
0xff
})
i32
:=
P2pComm
.
BytesToInt32
([]
byte
{
0xff
})
t
.
Log
(
i32
)
t
.
Log
(
i32
)
...
@@ -498,8 +499,8 @@ func TestSortArr(t *testing.T) {
...
@@ -498,8 +499,8 @@ func TestSortArr(t *testing.T) {
sort
.
Sort
(
Inventorys
)
sort
.
Sort
(
Inventorys
)
}
}
func
TestCreds
(
t
*
testing
.
T
){
func
TestCreds
(
t
*
testing
.
T
)
{
cert
:=
`-----BEGIN CERTIFICATE-----
cert
:=
`-----BEGIN CERTIFICATE-----
MIIDdTCCAl2gAwIBAgIJAJ1Z/S9L51/5MA0GCSqGSIb3DQEBCwUAMFExCzAJBgNV
MIIDdTCCAl2gAwIBAgIJAJ1Z/S9L51/5MA0GCSqGSIb3DQEBCwUAMFExCzAJBgNV
BAYTAkNOMQswCQYDVQQIDAJaSjELMAkGA1UEBwwCSFoxDDAKBgNVBAoMA0ZaTTEM
BAYTAkNOMQswCQYDVQQIDAJaSjELMAkGA1UEBwwCSFoxDDAKBgNVBAoMA0ZaTTEM
MAoGA1UECwwDRlpNMQwwCgYDVQQDDANMQlowHhcNMTgwNjI5MDMxNzEzWhcNMjgw
MAoGA1UECwwDRlpNMQwwCgYDVQQDDANMQlowHhcNMTgwNjI5MDMxNzEzWhcNMjgw
...
@@ -521,7 +522,7 @@ u8/Svlv5uH+2EqDGtYiDqmWlyGFJ3Q6lOGwCqRvhty7SYaHDZpV+10M32UuMBOOz
...
@@ -521,7 +522,7 @@ u8/Svlv5uH+2EqDGtYiDqmWlyGFJ3Q6lOGwCqRvhty7SYaHDZpV+10M32UuMBOOz
aHJJceqATq0U4NdzjbR0ygkApyDfv/5yfw==
aHJJceqATq0U4NdzjbR0ygkApyDfv/5yfw==
-----END CERTIFICATE-----
-----END CERTIFICATE-----
`
`
key
:=
`-----BEGIN RSA PRIVATE KEY-----
key
:=
`-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2OkNfozvtf5td2qgnDya9q+cR+wjD69ZuWe3DkPeOI2H/wRq
MIIEowIBAAKCAQEA2OkNfozvtf5td2qgnDya9q+cR+wjD69ZuWe3DkPeOI2H/wRq
yeasCj51qDDd6kQEVoyVfVtNMQgMQUxvHxSt1QU9rMp4zsm/aJaoeiYhJJH7l/FX
yeasCj51qDDd6kQEVoyVfVtNMQgMQUxvHxSt1QU9rMp4zsm/aJaoeiYhJJH7l/FX
LL4hYQ7LUSr2ee4at8fV9CCRh33DMpQ+50xGiWLtIfRtzAqiKV7P6RO+jz3iCted
LL4hYQ7LUSr2ee4at8fV9CCRh33DMpQ+50xGiWLtIfRtzAqiKV7P6RO+jz3iCted
...
@@ -549,35 +550,35 @@ RObdAoGBALP9HK7KuX7xl0cKBzOiXqnAyoMUfxvO30CsMI3DS0SrPc1p95OHswdu
...
@@ -549,35 +550,35 @@ RObdAoGBALP9HK7KuX7xl0cKBzOiXqnAyoMUfxvO30CsMI3DS0SrPc1p95OHswdu
/gd2v1Fb6oM82QBmWOFWaRSZj0UHZf8GvT09bs/SCSW4/hY/m4uC
/gd2v1Fb6oM82QBmWOFWaRSZj0UHZf8GvT09bs/SCSW4/hY/m4uC
-----END RSA PRIVATE KEY-----`
-----END RSA PRIVATE KEY-----`
certificate
,
err
:=
tls
.
X509KeyPair
([]
byte
(
cert
),
[]
byte
(
key
))
certificate
,
err
:=
tls
.
X509KeyPair
([]
byte
(
cert
),[]
byte
(
key
))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
cp
:=
x509
.
NewCertPool
()
cp
:=
x509
.
NewCertPool
()
if
!
cp
.
AppendCertsFromPEM
([]
byte
(
cert
)){
if
!
cp
.
AppendCertsFromPEM
([]
byte
(
cert
))
{
return
return
}
}
var
node
Node
var
node
Node
node
.
nodeInfo
=&
NodeInfo
{}
node
.
nodeInfo
=&
NodeInfo
{}
servCreds
:=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
servCreds
:=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
cliCreds
:=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
cliCreds
:=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
node
.
listenPort
=
3331
node
.
listenPort
=
3331
node
.
nodeInfo
.
servCreds
=
servCreds
node
.
nodeInfo
.
servCreds
=
servCreds
newListener
(
"tcp"
,
&
node
)
newListener
(
"tcp"
,
&
node
)
netAddr
,
err
:=
NewNetAddressString
(
"localhost:3331"
)
netAddr
,
err
:=
NewNetAddressString
(
"localhost:3331"
)
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
conn
,
err
:=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithTransportCredentials
(
cliCreds
))
conn
,
err
:=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithTransportCredentials
(
cliCreds
))
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
conn
)
assert
.
NotNil
(
t
,
conn
)
conn
.
Close
()
conn
.
Close
()
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
())
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
())
assert
.
NotNil
(
t
,
err
)
assert
.
NotNil
(
t
,
err
)
t
.
Log
(
"without creds"
,
err
)
t
.
Log
(
"without creds"
,
err
)
assert
.
Nil
(
t
,
conn
)
assert
.
Nil
(
t
,
conn
)
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithInsecure
())
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithInsecure
())
assert
.
Nil
(
t
,
err
)
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
conn
)
assert
.
NotNil
(
t
,
conn
)
}
}
plugin/p2p/gossip/p2pcli.go
View file @
defa98e1
...
@@ -561,7 +561,8 @@ func (m *Cli) GetNetInfo(msg *queue.Message, taskindex int64) {
...
@@ -561,7 +561,8 @@ func (m *Cli) GetNetInfo(msg *queue.Message, taskindex int64) {
// CheckPeerNatOk check peer is ok or not
// CheckPeerNatOk check peer is ok or not
func
(
m
*
Cli
)
CheckPeerNatOk
(
addr
string
,
info
*
NodeInfo
)
bool
{
func
(
m
*
Cli
)
CheckPeerNatOk
(
addr
string
,
info
*
NodeInfo
)
bool
{
//连接自己的地址信息做测试
//连接自己的地址信息做测试
return
!
(
len
(
P2pComm
.
AddrRouteble
([]
string
{
addr
},
info
.
channelVersion
,
nil
))
==
0
)
return
!
(
len
(
P2pComm
.
AddrRouteble
([]
string
{
addr
},
info
.
channelVersion
,
info
.
cliCreds
))
==
0
)
}
}
...
@@ -572,6 +573,7 @@ func (m *Cli) CheckSelf(addr string, nodeinfo *NodeInfo) bool {
...
@@ -572,6 +573,7 @@ func (m *Cli) CheckSelf(addr string, nodeinfo *NodeInfo) bool {
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
return
false
return
false
}
}
conn
,
err
:=
netaddr
.
DialTimeout
(
nodeinfo
.
channelVersion
,
nodeinfo
.
cliCreds
)
conn
,
err
:=
netaddr
.
DialTimeout
(
nodeinfo
.
channelVersion
,
nodeinfo
.
cliCreds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
false
return
false
...
...
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