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

Feature/snet rewrite #811

Merged
merged 59 commits into from
Jul 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
bb2a2f2
Make dependecies explicit: move out of config
i-hate-nicknames May 27, 2021
24ec49d
Move dmsg client to its own module
i-hate-nicknames May 31, 2021
240949b
Change dependencies to use dmsgC module
i-hate-nicknames May 31, 2021
1be07a1
Move snet into transport manager
i-hate-nicknames Jun 1, 2021
b0edebb
Comment out router tests
i-hate-nicknames Jun 1, 2021
30ed61d
Outline new snet structure inside transport package
i-hate-nicknames Jun 23, 2021
6eb6d1a
Add address structure
i-hate-nicknames Jun 23, 2021
12f303f
Add stcp client type
i-hate-nicknames Jun 23, 2021
3ad255e
Move tpConn and tpListener to network package
i-hate-nicknames Jun 23, 2021
6329db9
Unify tpconn.Conn and snet.Conn in network.Conn
i-hate-nicknames Jun 23, 2021
fec2378
Disable snet and use stcp client directly
i-hate-nicknames Jun 23, 2021
5f790b4
Fix connection encryption
i-hate-nicknames Jun 24, 2021
f0909ed
Fix connection type in network.Conn
i-hate-nicknames Jun 24, 2021
2000e2b
Simplify transport manager startup
i-hate-nicknames Jun 24, 2021
cabf5ed
Simplify transport manager close logic
i-hate-nicknames Jun 24, 2021
0a301c5
Refactor error handling in transport manager
i-hate-nicknames Jun 25, 2021
434cdfc
Add generic network client
i-hate-nicknames Jun 25, 2021
c282b14
Put handshake code to network client
i-hate-nicknames Jun 25, 2021
6ccadd7
Refactor handshakes into wrapConn method
i-hate-nicknames Jun 25, 2021
39587cc
Add stcpr client
i-hate-nicknames Jun 25, 2021
f0cfaf0
Refactor sending tcp events
i-hate-nicknames Jun 25, 2021
0f27b5f
Merge branch 'develop' into feature/snet-rewrite
i-hate-nicknames Jun 28, 2021
95561be
Fix event broadcaster
i-hate-nicknames Jun 28, 2021
83ba317
Initialize stcpr client
i-hate-nicknames Jun 28, 2021
b1bb4c1
Fix stcpr bind and resolve
i-hate-nicknames Jun 28, 2021
ad82e96
Switch to DialContext in stcpr client
i-hate-nicknames Jun 28, 2021
f70f903
Add sudph serve functionality
i-hate-nicknames Jun 28, 2021
0f18f4d
Add sudph dial functionality
i-hate-nicknames Jun 28, 2021
962cbbd
Factor out common sudph and stcpr code
i-hate-nicknames Jun 29, 2021
d6aad7f
Fix style, add comments and todos
i-hate-nicknames Jun 29, 2021
521bc59
Move address resolver to transport
i-hate-nicknames Jun 29, 2021
6772334
Remove address resolver from snet
i-hate-nicknames Jun 29, 2021
8f49205
Remove unused snet code
i-hate-nicknames Jun 29, 2021
fcad887
Move porter and handshake to network package
i-hate-nicknames Jun 29, 2021
63c834c
Move mock dialer to network package
i-hate-nicknames Jun 29, 2021
f5ebb9f
Switch to network.Type
i-hate-nicknames Jun 29, 2021
14934ba
Get rid of transport close callback
i-hate-nicknames Jun 29, 2021
a6c18b5
Add dmsg stub
i-hate-nicknames Jun 29, 2021
500f769
Add Connection and Listener interfaces
i-hate-nicknames Jun 30, 2021
07dac3a
Fix transport types
i-hate-nicknames Jun 30, 2021
b040b13
Implement dmsg client adapter
i-hate-nicknames Jun 30, 2021
c057ead
Fix dmsg client init and accept
i-hate-nicknames Jun 30, 2021
766230a
Fix rpc test
i-hate-nicknames Jul 1, 2021
682a59c
Decouple address resolver from tpconn
i-hate-nicknames Jul 1, 2021
3efb9c7
WIP add tests back
i-hate-nicknames Jul 1, 2021
498d169
Move GenKeyPairs to utils
i-hate-nicknames Jul 2, 2021
0423505
Remove tests that depend on snet.Network
i-hate-nicknames Jul 2, 2021
ed254ad
Merge branch 'develop' into feature/snet-rewrite
i-hate-nicknames Jul 2, 2021
4d8b803
Switch from dmsg.Type to network.DMSG
i-hate-nicknames Jul 2, 2021
1936d2b
Stop initialization when no dmsg config
i-hate-nicknames Jul 2, 2021
6998fde
Move dmsgc out of snet
i-hate-nicknames Jul 2, 2021
e325669
Cleanup ready todos
i-hate-nicknames Jul 2, 2021
f9577c0
Add handshake todo
i-hate-nicknames Jul 2, 2021
52a87f4
Fix todos in network package
i-hate-nicknames Jul 3, 2021
ea39be0
Fix linter errors
i-hate-nicknames Jul 3, 2021
d6e1db0
Remove unused code
i-hate-nicknames Jul 7, 2021
3e7ee0c
Fix lint errors
i-hate-nicknames Jul 7, 2021
bd371e4
Merge branch 'develop' into feature/snet-rewrite
i-hate-nicknames Jul 7, 2021
6bb7875
Merge branch 'develop' into feature/snet-rewrite
i-hate-nicknames Jul 8, 2021
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
15 changes: 7 additions & 8 deletions cmd/skywire-cli/commands/visor/transports.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ import (
"text/tabwriter"
"time"

"github.com/skycoin/dmsg"
"github.com/skycoin/dmsg/cipher"
"github.com/spf13/cobra"

"github.com/skycoin/skywire/cmd/skywire-cli/internal"
"github.com/skycoin/skywire/pkg/snet/directtp/tptypes"
"github.com/skycoin/skywire/pkg/transport/network"
"github.com/skycoin/skywire/pkg/visor"
)

Expand Down Expand Up @@ -113,15 +112,15 @@ var addTpCmd = &cobra.Command{

logger.Infof("Established %v transport to %v", transportType, pk)
} else {
transportTypes := []string{
tptypes.STCP,
tptypes.STCPR,
tptypes.SUDPH,
dmsg.Type,
transportTypes := []network.Type{
network.STCP,
network.STCPR,
network.SUDPH,
network.DMSG,
}

for _, transportType := range transportTypes {
tp, err = rpcClient().AddTransport(pk, transportType, public, timeout)
tp, err = rpcClient().AddTransport(pk, string(transportType), public, timeout)
if err == nil {
logger.Infof("Established %v transport to %v", transportType, pk)
break
Expand Down
26 changes: 26 additions & 0 deletions pkg/app/appevent/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package appevent

import "context"

// SendTCPDial sends tcp dial event
func (eb *Broadcaster) SendTCPDial(ctx context.Context, remoteNet, remoteAddr string) {
data := TCPDialData{RemoteNet: remoteNet, RemoteAddr: remoteAddr}
event := NewEvent(TCPDial, data)
eb.sendEvent(ctx, event)
}

// SendTPClose sends transport close event
func (eb *Broadcaster) SendTPClose(ctx context.Context, netType, addr string) {
data := TCPCloseData{RemoteNet: string(netType), RemoteAddr: addr}
event := NewEvent(TCPClose, data)
if err := eb.Broadcast(context.Background(), event); err != nil {
eb.log.WithError(err).Errorln("Failed to broadcast TCPClose event")
}
}

func (eb *Broadcaster) sendEvent(_ context.Context, event *Event) {
err := eb.Broadcast(context.Background(), event) //nolint:errcheck
if err != nil {
eb.log.Warn("Failed to broadcast event: %v", event)
}
}
6 changes: 3 additions & 3 deletions pkg/app/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"github.com/skycoin/skywire/pkg/app/appserver"
"github.com/skycoin/skywire/pkg/app/idmanager"
"github.com/skycoin/skywire/pkg/routing"
"github.com/skycoin/skywire/pkg/snet/snettest"
"github.com/skycoin/skywire/pkg/util/cipherutil"
)

func TestConn_Read(t *testing.T) {
Expand Down Expand Up @@ -175,7 +175,7 @@ func (p *wrappedConn) RemoteAddr() net.Addr {
func TestConn_TestConn(t *testing.T) {
mp := func() (net.Conn, net.Conn, func(), error) {
netType := appnet.TypeSkynet
keys := snettest.GenKeyPairs(2)
keys := cipherutil.GenKeyPairs(2)
fmt.Printf("C1 Local: %s\n", keys[0].PK)
fmt.Printf("C2 Local: %s\n", keys[1].PK)
p1, p2 := net.Pipe()
Expand Down Expand Up @@ -219,7 +219,7 @@ func TestConn_TestConn(t *testing.T) {

rpcS := rpc.NewServer()

appKeys := snettest.GenKeyPairs(2)
appKeys := cipherutil.GenKeyPairs(2)

var (
procKey1 appcommon.ProcKey
Expand Down
42 changes: 42 additions & 0 deletions pkg/dmsgc/dmsgc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dmsgc

import (
"context"

"github.com/skycoin/dmsg"
"github.com/skycoin/dmsg/cipher"
"github.com/skycoin/dmsg/disc"
"github.com/skycoin/skycoin/src/util/logging"

"github.com/skycoin/skywire/pkg/app/appevent"
)

// DmsgConfig defines config for Dmsg network.
type DmsgConfig struct {
Discovery string `json:"discovery"`
SessionsCount int `json:"sessions_count"`
}

// New makes new dmsg client from configuration
func New(pk cipher.PubKey, sk cipher.SecKey, eb *appevent.Broadcaster, conf *DmsgConfig) *dmsg.Client {
dmsgConf := &dmsg.Config{
MinSessions: conf.SessionsCount,
Callbacks: &dmsg.ClientCallbacks{
OnSessionDial: func(network, addr string) error {
data := appevent.TCPDialData{RemoteNet: network, RemoteAddr: addr}
event := appevent.NewEvent(appevent.TCPDial, data)
_ = eb.Broadcast(context.Background(), event) //nolint:errcheck
// @evanlinjin: An error is not returned here as this will cancel the session dial.
return nil
},
OnSessionDisconnect: func(network, addr string, _ error) {
data := appevent.TCPCloseData{RemoteNet: network, RemoteAddr: addr}
event := appevent.NewEvent(appevent.TCPClose, data)
_ = eb.Broadcast(context.Background(), event) //nolint:errcheck
},
},
}
dmsgC := dmsg.NewClient(pk, sk, disc.NewHTTP(conf.Discovery), dmsgConf)
dmsgC.SetLogger(logging.MustGetLogger("dmsgC"))
return dmsgC
}
Loading