save working solution
This commit is contained in:
@@ -629,7 +629,7 @@ func (t *tun) listen(link *link) {
|
||||
s, exists = t.getSession(channel, "listener")
|
||||
// only return accept to the session
|
||||
case mtype == "accept":
|
||||
log.Debugf("Received accept message for %s %s", channel, sessionId)
|
||||
log.Debugf("Received accept message for channel: %s session: %s", channel, sessionId)
|
||||
s, exists = t.getSession(channel, sessionId)
|
||||
if exists && s.accepted {
|
||||
continue
|
||||
@@ -649,7 +649,7 @@ func (t *tun) listen(link *link) {
|
||||
|
||||
// bail if no session or listener has been found
|
||||
if !exists {
|
||||
log.Debugf("Tunnel skipping no session %s %s exists", channel, sessionId)
|
||||
log.Debugf("Tunnel skipping no channel: %s session: %s exists", channel, sessionId)
|
||||
// drop it, we don't care about
|
||||
// messages we don't know about
|
||||
continue
|
||||
@@ -665,7 +665,7 @@ func (t *tun) listen(link *link) {
|
||||
// otherwise process
|
||||
}
|
||||
|
||||
log.Debugf("Tunnel using channel %s session %s type %s", s.channel, s.session, mtype)
|
||||
log.Debugf("Tunnel using channel: %s session: %s type: %s", s.channel, s.session, mtype)
|
||||
|
||||
// construct a new transport message
|
||||
tmsg := &transport.Message{
|
||||
|
||||
@@ -71,7 +71,7 @@ func (t *tunListener) process() {
|
||||
switch m.mode {
|
||||
case Multicast, Broadcast:
|
||||
// use channel name if multicast/broadcast
|
||||
sessionId = m.channel
|
||||
sessionId = "multicast"
|
||||
log.Tracef("Tunnel listener using session %s for real session %s", sessionId, m.session)
|
||||
default:
|
||||
// use session id if unicast
|
||||
@@ -198,6 +198,10 @@ func (t *tunListener) Accept() (Session, error) {
|
||||
if !ok {
|
||||
return nil, io.EOF
|
||||
}
|
||||
// return without accept
|
||||
if c.mode != Unicast {
|
||||
return c, nil
|
||||
}
|
||||
// send back the accept
|
||||
if err := c.Accept(); err != nil {
|
||||
return nil, err
|
||||
|
||||
@@ -2,7 +2,6 @@ package tunnel
|
||||
|
||||
import (
|
||||
"encoding/hex"
|
||||
"errors"
|
||||
"io"
|
||||
"time"
|
||||
|
||||
@@ -344,7 +343,7 @@ func (s *session) Recv(m *transport.Message) error {
|
||||
|
||||
select {
|
||||
case <-s.closed:
|
||||
return errors.New("session is closed")
|
||||
return io.EOF
|
||||
// recv from backlog
|
||||
case msg = <-s.recv:
|
||||
}
|
||||
@@ -360,7 +359,10 @@ func (s *session) Recv(m *transport.Message) error {
|
||||
log.Debugf("Received %+v from recv backlog", msg)
|
||||
|
||||
// decrypt the received payload using the token
|
||||
body, err := Decrypt(msg.data.Body, s.token+s.channel+s.session)
|
||||
// we have to used msg.session because multicast has a shared
|
||||
// session id of "multicast" in this session struct on
|
||||
// the listener side
|
||||
body, err := Decrypt(msg.data.Body, s.token+s.channel+msg.session)
|
||||
if err != nil {
|
||||
log.Debugf("failed to decrypt message body: %v", err)
|
||||
return err
|
||||
@@ -376,7 +378,7 @@ func (s *session) Recv(m *transport.Message) error {
|
||||
return err
|
||||
}
|
||||
// encrypt the transport message payload
|
||||
val, err := Decrypt([]byte(h), s.token+s.channel+s.session)
|
||||
val, err := Decrypt([]byte(h), s.token+s.channel+msg.session)
|
||||
if err != nil {
|
||||
log.Debugf("failed to decrypt message header %s: %v", k, err)
|
||||
return err
|
||||
|
||||
Reference in New Issue
Block a user