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
Show 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 (
"bytes"
"encoding/binary"
"encoding/hex"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
"math/rand"
"net"
"strings"
"time"
"github.com/33cn/chain33/common/crypto"
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials"
)
// P2pComm p2p communication
...
...
@@ -78,6 +79,7 @@ func (c Comm) GetLocalAddr() string {
func
(
c
Comm
)
dialPeerWithAddress
(
addr
*
NetAddress
,
persistent
bool
,
node
*
Node
)
(
*
Peer
,
error
)
{
log
.
Debug
(
"dialPeerWithAddress"
)
conn
,
err
:=
addr
.
DialTimeout
(
node
.
nodeInfo
.
channelVersion
,
node
.
nodeInfo
.
cliCreds
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/p2p/gossip/listener.go
View file @
defa98e1
...
...
@@ -146,6 +146,7 @@ Retry:
opts
=
append
(
opts
,
msgRecvOp
,
msgSendOp
,
grpc
.
KeepaliveEnforcementPolicy
(
kaep
),
keepOp
,
maxStreams
,
StatsOp
)
if
node
.
nodeInfo
.
servCreds
!=
nil
{
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
nodeInfo
.
servCreds
))
}
dl
.
server
=
grpc
.
NewServer
(
opts
...
)
dl
.
p2pserver
=
pServer
...
...
plugin/p2p/gossip/net_test.go
View file @
defa98e1
...
...
@@ -28,7 +28,7 @@ func TestNetAddress(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
)
}
...
...
plugin/p2p/gossip/netaddress.go
View file @
defa98e1
...
...
@@ -7,11 +7,12 @@ package gossip
import
(
"context"
"fmt"
"google.golang.org/grpc/credentials"
"net"
"strconv"
"time"
"google.golang.org/grpc/credentials"
pb
"github.com/33cn/chain33/types"
"google.golang.org/grpc"
"google.golang.org/grpc/codes"
...
...
@@ -142,7 +143,7 @@ func isCompressSupport(err error) bool {
}
// 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
<-
P2pComm
.
GrpcConfig
()
...
...
@@ -156,16 +157,16 @@ func (na *NetAddress) DialTimeout(version int32,creds credentials.TransportCrede
maxMsgSize
:=
pb
.
MaxBlockSize
+
1024
*
1024
//配置SSL连接
var
secOpt
grpc
.
DialOption
if
creds
==
nil
{
secOpt
=
grpc
.
WithInsecure
()
}
else
{
secOpt
=
grpc
.
WithTransportCredentials
(
creds
)
if
creds
==
nil
{
secOpt
=
grpc
.
WithInsecure
()
}
else
{
secOpt
=
grpc
.
WithTransportCredentials
(
creds
)
}
conn
,
err
:=
grpc
.
Dial
(
na
.
String
(),
grpc
.
WithDefaultCallOptions
(
grpc
.
UseCompressor
(
"gzip"
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallRecvMsgSize
(
maxMsgSize
)),
grpc
.
WithDefaultCallOptions
(
grpc
.
MaxCallSendMsgSize
(
maxMsgSize
)),
grpc
.
WithServiceConfig
(
ch
),
keepaliveOp
,
timeoutOp
,
secOpt
)
grpc
.
WithServiceConfig
(
ch
),
keepaliveOp
,
timeoutOp
,
secOpt
)
if
err
!=
nil
{
log
.
Debug
(
"grpc DialCon"
,
"did not connect"
,
err
,
"addr"
,
na
.
String
())
return
nil
,
err
...
...
plugin/p2p/gossip/p2p_test.go
View file @
defa98e1
...
...
@@ -6,12 +6,13 @@ import (
"encoding/hex"
"encoding/json"
"fmt"
"google.golang.org/grpc/credentials"
"net"
"sort"
"sync/atomic"
"time"
"google.golang.org/grpc/credentials"
"github.com/33cn/chain33/p2p"
"github.com/33cn/chain33/p2p/utils"
...
...
@@ -367,7 +368,7 @@ func testGrpcStreamConns(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
)
i32
:=
P2pComm
.
BytesToInt32
([]
byte
{
0xff
})
t
.
Log
(
i32
)
...
...
@@ -498,8 +499,8 @@ func TestSortArr(t *testing.T) {
sort
.
Sort
(
Inventorys
)
}
func
TestCreds
(
t
*
testing
.
T
){
cert
:=
`-----BEGIN CERTIFICATE-----
func
TestCreds
(
t
*
testing
.
T
)
{
cert
:=
`-----BEGIN CERTIFICATE-----
MIIDdTCCAl2gAwIBAgIJAJ1Z/S9L51/5MA0GCSqGSIb3DQEBCwUAMFExCzAJBgNV
BAYTAkNOMQswCQYDVQQIDAJaSjELMAkGA1UEBwwCSFoxDDAKBgNVBAoMA0ZaTTEM
MAoGA1UECwwDRlpNMQwwCgYDVQQDDANMQlowHhcNMTgwNjI5MDMxNzEzWhcNMjgw
...
...
@@ -521,7 +522,7 @@ u8/Svlv5uH+2EqDGtYiDqmWlyGFJ3Q6lOGwCqRvhty7SYaHDZpV+10M32UuMBOOz
aHJJceqATq0U4NdzjbR0ygkApyDfv/5yfw==
-----END CERTIFICATE-----
`
key
:=
`-----BEGIN RSA PRIVATE KEY-----
key
:=
`-----BEGIN RSA PRIVATE KEY-----
MIIEowIBAAKCAQEA2OkNfozvtf5td2qgnDya9q+cR+wjD69ZuWe3DkPeOI2H/wRq
yeasCj51qDDd6kQEVoyVfVtNMQgMQUxvHxSt1QU9rMp4zsm/aJaoeiYhJJH7l/FX
LL4hYQ7LUSr2ee4at8fV9CCRh33DMpQ+50xGiWLtIfRtzAqiKV7P6RO+jz3iCted
...
...
@@ -549,35 +550,35 @@ RObdAoGBALP9HK7KuX7xl0cKBzOiXqnAyoMUfxvO30CsMI3DS0SrPc1p95OHswdu
/gd2v1Fb6oM82QBmWOFWaRSZj0UHZf8GvT09bs/SCSW4/hY/m4uC
-----END RSA PRIVATE KEY-----`
certificate
,
err
:=
tls
.
X509KeyPair
([]
byte
(
cert
),[]
byte
(
key
))
assert
.
Nil
(
t
,
err
)
certificate
,
err
:=
tls
.
X509KeyPair
([]
byte
(
cert
),
[]
byte
(
key
))
assert
.
Nil
(
t
,
err
)
cp
:=
x509
.
NewCertPool
()
if
!
cp
.
AppendCertsFromPEM
([]
byte
(
cert
)){
if
!
cp
.
AppendCertsFromPEM
([]
byte
(
cert
))
{
return
}
var
node
Node
node
.
nodeInfo
=&
NodeInfo
{}
servCreds
:=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
cliCreds
:=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
node
.
listenPort
=
3331
node
.
nodeInfo
.
servCreds
=
servCreds
newListener
(
"tcp"
,
&
node
)
netAddr
,
err
:=
NewNetAddressString
(
"localhost:3331"
)
assert
.
Nil
(
t
,
err
)
netAddr
,
err
:=
NewNetAddressString
(
"localhost:3331"
)
assert
.
Nil
(
t
,
err
)
conn
,
err
:=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithTransportCredentials
(
cliCreds
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
conn
)
conn
.
Close
()
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
())
assert
.
NotNil
(
t
,
err
)
t
.
Log
(
"without creds"
,
err
)
assert
.
Nil
(
t
,
conn
)
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithInsecure
())
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
conn
)
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
())
assert
.
NotNil
(
t
,
err
)
t
.
Log
(
"without creds"
,
err
)
assert
.
Nil
(
t
,
conn
)
conn
,
err
=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithInsecure
())
assert
.
Nil
(
t
,
err
)
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) {
// CheckPeerNatOk check peer is ok or not
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 {
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
return
false
}
conn
,
err
:=
netaddr
.
DialTimeout
(
nodeinfo
.
channelVersion
,
nodeinfo
.
cliCreds
)
if
err
!=
nil
{
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