Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rule expiration #152

Merged
merged 39 commits into from
Mar 2, 2020
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
5a5f896
Move rule activity update to after the packet successful propagation
Darkren Feb 6, 2020
08d7c1e
Start fixing
Darkren Feb 6, 2020
33ce059
Move a bit further
Darkren Feb 7, 2020
1ce164c
Update vendor
Darkren Feb 10, 2020
66fc6f4
Move routing table initialization inside the router. Proxy all visor …
Darkren Feb 10, 2020
f00eeec
Move rules GC routing from routing table to router
Darkren Feb 10, 2020
eabc996
Merge branch 'milestone2' of github.com:SkycoinProject/skywire-mainne…
Darkren Feb 10, 2020
4999644
Complete rules GC loop, remove old unused code, refactor a bit
Darkren Feb 10, 2020
32d2d0f
Fix non-pointer method call
Darkren Feb 10, 2020
b1577e2
Fix
Darkren Feb 10, 2020
adb3f91
Regenerate router mock
Darkren Feb 10, 2020
969f38b
Fix `router` tests, remove test for routing table clenup due to the c…
Darkren Feb 10, 2020
788915d
Update vendor
Darkren Feb 11, 2020
8505c2e
Add debug logs
Darkren Feb 11, 2020
f7c3fdf
Fix route group closing on timeout
Darkren Feb 11, 2020
14377af
Update vendor
Darkren Feb 13, 2020
2ee633f
Fix skychat conn removal, add A LOT OF debug logs
Darkren Feb 19, 2020
3e54cf4
Merge branch 'milestone2' of github.com:SkycoinProject/skywire-mainne…
Darkren Feb 20, 2020
ef49e27
Add debug logs, remove last `hashicorp/yamux` reference
Darkren Feb 20, 2020
d97be23
Disable yamux internal keep-alive for skysocks
Darkren Feb 20, 2020
7458daf
Fix packet forwarding from route group after a new route establishment
Darkren Feb 20, 2020
01257e4
Remove yamux internal keep-alive for skysocks client
Darkren Feb 20, 2020
1b82d1a
Fix keep-alive and close packets initial send
Darkren Feb 20, 2020
5704066
Update vendor
Darkren Feb 21, 2020
8b2d488
Fix the issue when establishing the already existing route. Probably
Darkren Feb 24, 2020
7da6f5e
Update vendor
Darkren Feb 25, 2020
3644c30
Change `io.EOF` to be `io.ErrClosedPipe` when RG is closed
Darkren Feb 25, 2020
a34c572
Update vendor
Darkren Feb 27, 2020
c95d27f
Update vendor
Darkren Feb 27, 2020
b5d6519
Fix skysocks client to handle remote visor restart properly
Darkren Feb 27, 2020
5f16007
Update vendor
Darkren Feb 28, 2020
6ffbd07
Refactor skysocks-client to preserve `skysocks.Client`'s original int…
Darkren Feb 28, 2020
07d02ec
Remove `github.com/pkg/errors` reference
Darkren Feb 28, 2020
9bbd802
Remove unused field from route group
Darkren Feb 28, 2020
049309b
Update vendor
Darkren Mar 1, 2020
c37bcea
Update vendor
Darkren Mar 2, 2020
ae700d4
Refactor debug logs
Darkren Mar 2, 2020
fc0c5ae
Merge branch 'milestone2' of github.com:SkycoinProject/skywire-mainne…
Darkren Mar 2, 2020
7b48f37
Reduce keep-alive interval and route timeout
Darkren Mar 2, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ require (
github.com/spf13/cobra v0.0.5
github.com/stretchr/testify v1.4.0
go.etcd.io/bbolt v1.3.3
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72
golang.org/x/crypto v0.0.0-20200208060501-ecb85df21340
golang.org/x/net v0.0.0-20191204025024-5ee1b9f4859a
golang.org/x/sys v0.0.0-20200202164722-d101bd2416d5 // indirect
)
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d h1:9FCpayM9Egr1baVnV1SX0H
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72 h1:+ELyKg6m8UBf0nPFSqD0mi7zUfwPyXo23HNjMnXPz7w=
golang.org/x/crypto v0.0.0-20200204104054-c9f3fb736b72/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/crypto v0.0.0-20200208060501-ecb85df21340 h1:KOcEaR10tFr7gdJV2GCKw8Os5yED1u1aOqHjOAb6d2Y=
golang.org/x/crypto v0.0.0-20200208060501-ecb85df21340/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
Expand Down
85 changes: 76 additions & 9 deletions pkg/router/mock_router.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 48 additions & 14 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,9 @@ type RouteGroup struct {
// - fwd/tps should have the same number of elements.
// - the corresponding element of tps should have tpID of the corresponding rule in fwd.
// - fwd references 'ForwardRule' rules for writes.
fwd []routing.Rule // forward rules (for writing)
rvs []routing.Rule // reverse rules (for reading)
fwd []routing.Rule // forward rules (for writing)
rvs []routing.Rule // reverse rules (for reading)
rvsRouteLastActivity time.Time

lastSent int64

Expand All @@ -93,9 +94,10 @@ type RouteGroup struct {
writeDeadline deadline.PipeDeadline

// used as a bool to indicate if this particular route group initiated close loop
closeInitiated int32
remoteClosed chan struct{}
closed chan struct{}
closeInitiated int32
remoteClosedOnce sync.Once
remoteClosed chan struct{}
closed chan struct{}
// used to wait for all the `Close` packets to run through the loop and come back
closeDone sync.WaitGroup
}
Expand Down Expand Up @@ -418,7 +420,8 @@ func (rg *RouteGroup) close(code routing.CloseCode) error {
close(rg.closed)
}

close(rg.remoteClosed)
rg.setRemoteClosed()

rg.readChMu.Lock()
close(rg.readCh)
rg.readChMu.Unlock()
Expand All @@ -427,6 +430,33 @@ func (rg *RouteGroup) close(code routing.CloseCode) error {
return nil
}

func (rg *RouteGroup) handlePacket(packet routing.Packet) error {
rg.mu.Lock()
// no need to check rule expiry, since router won't allow packet in
// in case it's expired, so simply update the activity
rg.rvsRouteLastActivity = time.Now()
rg.mu.Unlock()

switch packet.Type() {
case routing.ClosePacket:
return rg.handleClosePacket(routing.CloseCode(packet.Payload()[0]))
case routing.DataPacket:
return rg.handleDataPacket(packet)
}

return nil
}

func (rg *RouteGroup) handleDataPacket(packet routing.Packet) error {
select {
case <-rg.closed:
return io.ErrClosedPipe
case rg.readCh <- packet.Payload():
}

return nil
}

func (rg *RouteGroup) handleClosePacket(code routing.CloseCode) error {
rg.logger.Infof("Got close packet with code %d", code)

Expand Down Expand Up @@ -475,19 +505,23 @@ func (rg *RouteGroup) isCloseInitiator() bool {
return atomic.LoadInt32(&rg.closeInitiated) == 1
}

func (rg *RouteGroup) isRemoteClosed() bool {
select {
case <-rg.remoteClosed:
return true
default:
}
func (rg *RouteGroup) setRemoteClosed() {
rg.remoteClosedOnce.Do(func() {
close(rg.remoteClosed)
})
}

return false
func (rg *RouteGroup) isRemoteClosed() bool {
return chanClosed(rg.remoteClosed)
}

func (rg *RouteGroup) isClosed() bool {
return chanClosed(rg.closed)
}

func chanClosed(ch chan struct{}) bool {
select {
case <-rg.closed:
case <-ch:
return true
default:
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/route_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ func safeSend(ctx context.Context, to *RouteGroup, payload []byte) (keepSending
}

func createRouteGroup(cfg *RouteGroupConfig) *RouteGroup {
rt := routing.NewTable(routing.DefaultConfig())
rt := routing.NewTable()

pk1, _ := cipher.GenerateKeyPair()
pk2, _ := cipher.GenerateKeyPair()
Expand Down
Loading