-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #811 from i-hate-nicknames/feature/snet-rewrite
Feature/snet rewrite
- Loading branch information
Showing
67 changed files
with
1,578 additions
and
3,636 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.