Define tunnel errors

This commit is contained in:
Milos Gajdos 2020-01-13 20:06:02 +00:00
parent 770c7686ba
commit efcac3d009
No known key found for this signature in database
GPG Key ID: 8B31058CC55DFD4F
2 changed files with 10 additions and 4 deletions

View File

@ -384,7 +384,7 @@ func (t *tun) process() {
// if the link is not connected skip it // if the link is not connected skip it
if !connected { if !connected {
log.Debugf("Link for node %s not connected", id) log.Debugf("Link for node %s not connected", id)
err = errors.New("link not connected") err = ErrLinkDisconnected
continue continue
} }
@ -392,14 +392,14 @@ func (t *tun) process() {
// and the message is being sent outbound via // and the message is being sent outbound via
// a dialled connection don't use this link // a dialled connection don't use this link
if loopback && msg.outbound { if loopback && msg.outbound {
err = errors.New("link is loopback") err = ErrLinkLoopback
continue continue
} }
// if the message was being returned by the loopback listener // if the message was being returned by the loopback listener
// send it back up the loopback link only // send it back up the loopback link only
if msg.loopback && !loopback { if msg.loopback && !loopback {
err = errors.New("link is not loopback") err = ErrLinkRemote
continue continue
} }
@ -414,7 +414,7 @@ func (t *tun) process() {
// this is where we explicitly set the link // this is where we explicitly set the link
// in a message received via the listen method // in a message received via the listen method
if len(msg.link) > 0 && id != msg.link { if len(msg.link) > 0 && id != msg.link {
err = errors.New("link not found") err = ErrLinkNotFound
continue continue
} }
} }

View File

@ -26,6 +26,12 @@ var (
ErrDiscoverChan = errors.New("failed to discover channel") ErrDiscoverChan = errors.New("failed to discover channel")
// ErrLinkNotFound is returned when a link is specified at dial time and does not exist // ErrLinkNotFound is returned when a link is specified at dial time and does not exist
ErrLinkNotFound = errors.New("link not found") ErrLinkNotFound = errors.New("link not found")
// ErrLinkDisconnected is returned when a link we attempt to send to is disconnected
ErrLinkDisconnected = errors.New("link not connected")
// ErrLinkLoppback is returned when attempting to send an outbound message over loopback link
ErrLinkLoopback = errors.New("link is loopback")
// ErrLinkRemote is returned when attempting to send a loopback message over remote link
ErrLinkRemote = errors.New("link is remote")
// 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 is for when theres a nonce error