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
Hide 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 (
...
@@ -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
...
@@ -25,7 +26,7 @@ var P2pComm Comm
...
@@ -25,7 +26,7 @@ var P2pComm Comm
type
Comm
struct
{}
type
Comm
struct
{}
// AddrRouteble address router ,return enbale address
// 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
var
enableAddrs
[]
string
for
_
,
addr
:=
range
addrs
{
for
_
,
addr
:=
range
addrs
{
...
@@ -34,7 +35,7 @@ func (Comm) AddrRouteble(addrs []string, version int32,creds credentials.Transpo
...
@@ -34,7 +35,7 @@ func (Comm) AddrRouteble(addrs []string, version int32,creds credentials.Transpo
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
log
.
Error
(
"AddrRouteble"
,
"NewNetAddressString"
,
err
.
Error
())
continue
continue
}
}
conn
,
err
:=
netaddr
.
DialTimeout
(
version
,
creds
)
conn
,
err
:=
netaddr
.
DialTimeout
(
version
,
creds
)
if
err
!=
nil
{
if
err
!=
nil
{
//log.Error("AddrRouteble", "DialTimeout", err.Error())
//log.Error("AddrRouteble", "DialTimeout", err.Error())
continue
continue
...
@@ -77,7 +78,7 @@ func (c Comm) GetLocalAddr() string {
...
@@ -77,7 +78,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
.
cliCreds
)
conn
,
err
:=
addr
.
DialTimeout
(
node
.
nodeInfo
.
channelVersion
,
node
.
cliCreds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
plugin/p2p/gossip/listener.go
View file @
43d0c91f
...
@@ -144,8 +144,8 @@ Retry:
...
@@ -144,8 +144,8 @@ Retry:
keepOp
:=
grpc
.
KeepaliveParams
(
keepparm
)
keepOp
:=
grpc
.
KeepaliveParams
(
keepparm
)
StatsOp
:=
grpc
.
StatsHandler
(
&
statshandler
{})
StatsOp
:=
grpc
.
StatsHandler
(
&
statshandler
{})
opts
=
append
(
opts
,
msgRecvOp
,
msgSendOp
,
grpc
.
KeepaliveEnforcementPolicy
(
kaep
),
keepOp
,
maxStreams
,
StatsOp
)
opts
=
append
(
opts
,
msgRecvOp
,
msgSendOp
,
grpc
.
KeepaliveEnforcementPolicy
(
kaep
),
keepOp
,
maxStreams
,
StatsOp
)
if
node
.
servCreds
!=
nil
{
if
node
.
servCreds
!=
nil
{
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
servCreds
))
opts
=
append
(
opts
,
grpc
.
Creds
(
node
.
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 @
43d0c91f
...
@@ -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 @
43d0c91f
...
@@ -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 @
43d0c91f
...
@@ -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,32 +550,31 @@ RObdAoGBALP9HK7KuX7xl0cKBzOiXqnAyoMUfxvO30CsMI3DS0SrPc1p95OHswdu
...
@@ -549,32 +550,31 @@ 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
.
servCreds
=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
node
.
servCreds
=
credentials
.
NewServerTLSFromCert
(
&
certificate
)
node
.
cliCreds
=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
node
.
cliCreds
=
credentials
.
NewClientTLSFromCert
(
cp
,
""
)
node
.
listenPort
=
3331
node
.
listenPort
=
3331
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
(
node
.
cliCreds
))
conn
,
err
:=
grpc
.
Dial
(
netAddr
.
String
(),
grpc
.
WithTransportCredentials
(
node
.
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 @
43d0c91f
...
@@ -561,7 +561,7 @@ func (m *Cli) GetNetInfo(msg *queue.Message, taskindex int64) {
...
@@ -561,7 +561,7 @@ 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
,
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 {
...
@@ -572,7 +572,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
,
m
.
network
.
node
.
cliCreds
)
conn
,
err
:=
netaddr
.
DialTimeout
(
nodeinfo
.
channelVersion
,
m
.
network
.
node
.
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