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
43d0c91f
Commit
43d0c91f
authored
Feb 05, 2021
by
vipwzw
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
auto ci
parent
377c9536
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
44 additions
and
42 deletions
+44
-42
common.go
plugin/p2p/gossip/common.go
+8
-7
listener.go
plugin/p2p/gossip/listener.go
+2
-2
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
+23
-23
p2pcli.go
plugin/p2p/gossip/p2pcli.go
+2
-2
No files found.
plugin/p2p/gossip/common.go
View file @
43d0c91f
...
...
@@ -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
...
...
@@ -25,7 +26,7 @@ var P2pComm Comm
type
Comm
struct
{}
// AddrRouteble address router ,return enbale address
func
(
Comm
)
AddrRouteble
(
addrs
[]
string
,
version
int32
,
creds
credentials
.
TransportCredentials
)
[]
string
{
func
(
Comm
)
AddrRouteble
(
addrs
[]
string
,
version
int32
,
creds
credentials
.
TransportCredentials
)
[]
string
{
var
enableAddrs
[]
string
for
_
,
addr
:=
range
addrs
{
...
...
@@ -34,7 +35,7 @@ func (Comm) AddrRouteble(addrs []string, version int32,creds credentials.Transpo
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
continue
}
conn
,
err
:=
netaddr
.
DialTimeout
(
version
,
creds
)
conn
,
err
:=
netaddr
.
DialTimeout
(
version
,
creds
)
if
err
!=
nil
{
//log.Error("AddrRouteble", "DialTimeout", err.Error())
continue
...
...
@@ -77,7 +78,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
.
cliCreds
)
conn
,
err
:=
addr
.
DialTimeout
(
node
.
nodeInfo
.
channelVersion
,
node
.
cliCreds
)
if
err
!=
nil
{
return
nil
,
err
}
...
...
plugin/p2p/gossip/listener.go
View file @
43d0c91f
...
...
@@ -144,8 +144,8 @@ Retry:
keepOp
:=
grpc
.
KeepaliveParams
(
keepparm
)
StatsOp
:=
grpc
.
StatsHandler
(
&
statshandler
{})
opts
=
append
(
opts
,
msgRecvOp
,
msgSendOp
,
grpc
.
KeepaliveEnforcementPolicy
(
kaep
),
keepOp
,
maxStreams
,
StatsOp
)
if
node
.
servCreds
!=
nil
{
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
servCreds
))
if
node
.
servCreds
!=
nil
{
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
servCreds
))
}
dl
.
server
=
grpc
.
NewServer
(
opts
...
)
dl
.
p2pserver
=
pServer
...
...
plugin/p2p/gossip/net_test.go
View file @
43d0c91f
...
...
@@ -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 @
43d0c91f
...
...
@@ -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 @
43d0c91f
...
...
@@ -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,32 +550,31 @@ 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
.
servCreds
=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
node
.
cliCreds
=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
node
.
servCreds
=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
node
.
cliCreds
=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
node
.
listenPort
=
3331
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
(
node
.
cliCreds
))
assert
.
Nil
(
t
,
err
)
assert
.
NotNil
(
t
,
conn
)
conn
,
err
:=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithTransportCredentials
(
node
.
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 @
43d0c91f
...
...
@@ -561,7 +561,7 @@ 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
,
m
.
network
.
node
.
cliCreds
))
==
0
)
return
!
(
len
(
P2pComm
.
AddrRouteble
([]
string
{
addr
},
info
.
channelVersion
,
m
.
network
.
node
.
cliCreds
))
==
0
)
}
...
...
@@ -572,7 +572,7 @@ func (m *Cli) CheckSelf(addr string, nodeinfo *NodeInfo) bool {
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
return
false
}
conn
,
err
:=
netaddr
.
DialTimeout
(
nodeinfo
.
channelVersion
,
m
.
network
.
node
.
cliCreds
)
conn
,
err
:=
netaddr
.
DialTimeout
(
nodeinfo
.
channelVersion
,
m
.
network
.
node
.
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