good morning!!!!
Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
B
bor
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Harbor Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
open
bor
Commits
f9aa1cd2
Commit
f9aa1cd2
authored
6 years ago
by
Anton Evangelatov
Committed by
Viktor Trón
6 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Revert "swarm/network: Use actual remote peer ip in underlay (#19137)" (#19193)
This reverts commit
460d206f
.
parent
b797dd07
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
swarm/network/protocol.go
+1
-20
1 addition, 20 deletions
swarm/network/protocol.go
swarm/network/protocol_test.go
+0
-26
0 additions, 26 deletions
swarm/network/protocol_test.go
with
1 addition
and
46 deletions
swarm/network/protocol.go
+
1
−
20
View file @
f9aa1cd2
...
...
@@ -21,7 +21,6 @@ import (
"errors"
"fmt"
"net"
"regexp"
"sync"
"time"
...
...
@@ -40,8 +39,6 @@ const (
bzzHandshakeTimeout
=
3000
*
time
.
Millisecond
)
var
regexpEnodeIP
=
regexp
.
MustCompile
(
"@(.+):([0-9]+)"
)
// BzzSpec is the spec of the generic swarm handshake
var
BzzSpec
=
&
protocols
.
Spec
{
Name
:
"bzz"
,
...
...
@@ -217,26 +214,10 @@ func (b *Bzz) performHandshake(p *protocols.Peer, handshake *HandshakeMsg) error
return
err
}
handshake
.
peerAddr
=
rsh
.
(
*
HandshakeMsg
)
.
Addr
sanitizeEnodeRemote
(
p
.
RemoteAddr
(),
handshake
.
peerAddr
)
handshake
.
LightNode
=
rsh
.
(
*
HandshakeMsg
)
.
LightNode
return
nil
}
// the remote enode string may advertise arbitrary host information (e.g. localhost)
// this method ensures that the addr of the peer will be the one
// applicable on the interface the connection came in on
// it modifies the passed bzzaddr in place, and returns the same pointer
func
sanitizeEnodeRemote
(
paddr
net
.
Addr
,
baddr
*
BzzAddr
)
{
hsSubmatch
:=
regexpEnodeIP
.
FindSubmatch
(
baddr
.
UAddr
)
ip
,
_
,
err
:=
net
.
SplitHostPort
(
paddr
.
String
())
// since we expect nothing else than ipv4 here, a panic on missing submatch is desired
if
err
==
nil
&&
string
(
hsSubmatch
[
1
])
!=
ip
{
remoteStr
:=
fmt
.
Sprintf
(
"@%s:%s"
,
ip
,
string
(
hsSubmatch
[
2
]))
log
.
Debug
(
"rewrote peer uaddr host/port"
,
"addr"
,
baddr
)
baddr
.
UAddr
=
regexpEnodeIP
.
ReplaceAll
(
baddr
.
UAddr
,
[]
byte
(
remoteStr
))
}
}
// runBzz is the p2p protocol run function for the bzz base protocol
// that negotiates the bzz handshake
func
(
b
*
Bzz
)
runBzz
(
p
*
p2p
.
Peer
,
rw
p2p
.
MsgReadWriter
)
error
{
...
...
@@ -343,7 +324,7 @@ func (b *Bzz) GetOrCreateHandshake(peerID enode.ID) (*HandshakeMsg, bool) {
init
:
make
(
chan
bool
,
1
),
done
:
make
(
chan
struct
{}),
}
// when hand
s
hake is first created for a remote peer
// when handh
s
ake is first created for a remote peer
// it is initialised with the init
handshake
.
init
<-
true
b
.
handshakes
[
peerID
]
=
handshake
...
...
This diff is collapsed.
Click to expand it.
swarm/network/protocol_test.go
+
0
−
26
View file @
f9aa1cd2
...
...
@@ -17,15 +17,12 @@
package
network
import
(
"bytes"
"flag"
"fmt"
"net"
"os"
"testing"
"time"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum/go-ethereum/log"
"github.com/ethereum/go-ethereum/p2p"
"github.com/ethereum/go-ethereum/p2p/enode"
...
...
@@ -254,26 +251,3 @@ func TestBzzHandshakeLightNode(t *testing.T) {
})
}
}
// Tests the overwriting of localhost enode in handshake if actual remote ip is known
// (swarm.network/protocol.go:sanitizeEnodeRemote)
func
TestSanitizeEnodeRemote
(
t
*
testing
.
T
)
{
pk
,
err
:=
crypto
.
GenerateKey
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
remoteIP
:=
net
.
IPv4
(
0x80
,
0x40
,
0x20
,
0x10
)
remoteAddr
:=
net
.
TCPAddr
{
IP
:
remoteIP
,
Port
:
30399
,
}
nodLocal
:=
enode
.
NewV4
(
&
pk
.
PublicKey
,
net
.
IPv4
(
0x7f
,
0x00
,
0x00
,
0x01
),
30341
,
30341
)
nodRemote
:=
enode
.
NewV4
(
&
pk
.
PublicKey
,
remoteIP
,
30341
,
30341
)
baddr
:=
RandomAddr
()
oldUAddr
:=
[]
byte
(
nodLocal
.
String
())
baddr
.
UAddr
=
oldUAddr
sanitizeEnodeRemote
(
&
remoteAddr
,
baddr
)
if
!
bytes
.
Equal
(
baddr
.
UAddr
,
[]
byte
(
nodRemote
.
String
()))
{
t
.
Fatalf
(
"insane address. expected %v, got %v"
,
nodRemote
.
String
(),
string
(
baddr
.
UAddr
))
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment