fix more broken cruft
This commit is contained in:
parent
df728aaddd
commit
7bd50cd251
@ -331,7 +331,9 @@ func (n *network) advertise(advertChan <-chan *router.Advert) {
|
|||||||
// someone requested the route
|
// someone requested the route
|
||||||
n.sendTo("advert", ControlChannel, peer, msg)
|
n.sendTo("advert", ControlChannel, peer, msg)
|
||||||
default:
|
default:
|
||||||
// no one to send to
|
if err := n.sendMsg("advert", ControlChannel, msg); err != nil {
|
||||||
|
log.Debugf("Network failed to advertise routes: %v", err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
case <-n.closed:
|
case <-n.closed:
|
||||||
return
|
return
|
||||||
@ -958,7 +960,7 @@ func (n *network) manage() {
|
|||||||
return
|
return
|
||||||
case <-announce.C:
|
case <-announce.C:
|
||||||
// jitter
|
// jitter
|
||||||
j := rand.Int63n(int64(AnnounceTime / 2))
|
j := rand.Int63n(int64(AnnounceTime.Seconds() / 2.0))
|
||||||
time.Sleep(time.Duration(j) * time.Second)
|
time.Sleep(time.Duration(j) * time.Second)
|
||||||
|
|
||||||
// TODO: intermittently flip between peer selection
|
// TODO: intermittently flip between peer selection
|
||||||
|
@ -60,6 +60,11 @@ func Decrypt(data []byte, key string) ([]byte, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
nonceSize := gcm.NonceSize()
|
nonceSize := gcm.NonceSize()
|
||||||
|
|
||||||
|
if len(data) < nonceSize {
|
||||||
|
return nil, ErrDecryptingData
|
||||||
|
}
|
||||||
|
|
||||||
// NOTE: we need to parse out nonce from the payload
|
// NOTE: we need to parse out nonce from the payload
|
||||||
// we prepend the nonce to every encrypted payload
|
// we prepend the nonce to every encrypted payload
|
||||||
nonce, ciphertext := data[:nonceSize], data[nonceSize:]
|
nonce, ciphertext := data[:nonceSize], data[nonceSize:]
|
||||||
|
@ -229,7 +229,7 @@ func (t *tun) manageLink(link *link) {
|
|||||||
|
|
||||||
wait := func(d time.Duration) {
|
wait := func(d time.Duration) {
|
||||||
// jitter
|
// jitter
|
||||||
j := rand.Int63n(int64(d / 2))
|
j := rand.Int63n(int64(d.Seconds() / 2.0))
|
||||||
time.Sleep(time.Duration(j) * time.Second)
|
time.Sleep(time.Duration(j) * time.Second)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,15 +387,6 @@ func (t *tun) process() {
|
|||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case msg := <-t.send:
|
case msg := <-t.send:
|
||||||
// no links yet
|
|
||||||
if len(links) == 0 {
|
|
||||||
// TODO: should we block here rather than throwing away messages...
|
|
||||||
// Or should we return an error?
|
|
||||||
log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel)
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
|
|
||||||
// build a list of links to send to
|
// build a list of links to send to
|
||||||
var sendTo []*link
|
var sendTo []*link
|
||||||
var err error
|
var err error
|
||||||
@ -456,7 +447,7 @@ func (t *tun) process() {
|
|||||||
|
|
||||||
// no links to send to
|
// no links to send to
|
||||||
if len(sendTo) == 0 {
|
if len(sendTo) == 0 {
|
||||||
log.Log("no links")
|
log.Debugf("No links to send message type: %s channel: %s", msg.typ, msg.channel)
|
||||||
t.respond(msg, err)
|
t.respond(msg, err)
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
@ -532,6 +523,7 @@ func (t *tun) sendTo(links []*link, msg *message) error {
|
|||||||
// make a copy
|
// make a copy
|
||||||
m := &transport.Message{
|
m := &transport.Message{
|
||||||
Header: make(map[string]string),
|
Header: make(map[string]string),
|
||||||
|
Body: make([]byte, len(newMsg.Body)),
|
||||||
}
|
}
|
||||||
copy(m.Body, newMsg.Body)
|
copy(m.Body, newMsg.Body)
|
||||||
for k, v := range newMsg.Header {
|
for k, v := range newMsg.Header {
|
||||||
|
@ -2,6 +2,7 @@ package tunnel
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
|
"sync"
|
||||||
|
|
||||||
"github.com/micro/go-micro/util/log"
|
"github.com/micro/go-micro/util/log"
|
||||||
)
|
)
|
||||||
@ -13,14 +14,16 @@ type tunListener struct {
|
|||||||
token string
|
token string
|
||||||
// the accept channel
|
// the accept channel
|
||||||
accept chan *session
|
accept chan *session
|
||||||
// the channel to close
|
|
||||||
closed chan bool
|
|
||||||
// the tunnel closed channel
|
// the tunnel closed channel
|
||||||
tunClosed chan bool
|
tunClosed chan bool
|
||||||
// the listener session
|
// the listener session
|
||||||
session *session
|
session *session
|
||||||
// del func to kill listener
|
// del func to kill listener
|
||||||
delFunc func()
|
delFunc func()
|
||||||
|
|
||||||
|
sync.RWMutex
|
||||||
|
// the channel to close
|
||||||
|
closed chan bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *tunListener) process() {
|
func (t *tunListener) process() {
|
||||||
@ -49,7 +52,7 @@ func (t *tunListener) process() {
|
|||||||
var sessionId string
|
var sessionId string
|
||||||
var linkId string
|
var linkId string
|
||||||
|
|
||||||
switch m.mode {
|
switch t.session.mode {
|
||||||
case Multicast:
|
case Multicast:
|
||||||
sessionId = "multicast"
|
sessionId = "multicast"
|
||||||
linkId = "multicast"
|
linkId = "multicast"
|
||||||
@ -87,7 +90,7 @@ func (t *tunListener) process() {
|
|||||||
// the link the message was received on
|
// the link the message was received on
|
||||||
link: linkId,
|
link: linkId,
|
||||||
// set the connection mode
|
// set the connection mode
|
||||||
mode: m.mode,
|
mode: t.session.mode,
|
||||||
// close chan
|
// close chan
|
||||||
closed: make(chan bool),
|
closed: make(chan bool),
|
||||||
// recv called by the acceptor
|
// recv called by the acceptor
|
||||||
@ -115,6 +118,11 @@ func (t *tunListener) process() {
|
|||||||
|
|
||||||
switch m.typ {
|
switch m.typ {
|
||||||
case "close":
|
case "close":
|
||||||
|
// don't close multicast sessions
|
||||||
|
if sess.mode > Unicast {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
// received a close message
|
// received a close message
|
||||||
select {
|
select {
|
||||||
// check if the session is closed
|
// check if the session is closed
|
||||||
@ -154,6 +162,9 @@ func (t *tunListener) Channel() string {
|
|||||||
|
|
||||||
// Close closes tunnel listener
|
// Close closes tunnel listener
|
||||||
func (t *tunListener) Close() error {
|
func (t *tunListener) Close() error {
|
||||||
|
t.Lock()
|
||||||
|
defer t.Unlock()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-t.closed:
|
case <-t.closed:
|
||||||
return nil
|
return nil
|
||||||
|
@ -28,6 +28,8 @@ var (
|
|||||||
ErrLinkNotFound = errors.New("link not found")
|
ErrLinkNotFound = errors.New("link not found")
|
||||||
// ErrReadTimeout is a timeout on session.Recv
|
// ErrReadTimeout is a timeout on session.Recv
|
||||||
ErrReadTimeout = errors.New("read timeout")
|
ErrReadTimeout = errors.New("read timeout")
|
||||||
|
// ErrDecryptingData is for when theres a nonce error
|
||||||
|
ErrDecryptingData = errors.New("error decrypting data")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Mode of the session
|
// Mode of the session
|
||||||
|
Loading…
Reference in New Issue
Block a user