Forward a packet with sleeve if the source or dest peer lacks a short ID

This commit is contained in:
David Wragg committed 2015-10-14 13:53:59 +01:00
1 parent e702234fdc
commit 35141a4aef
3 files changed
+43 -25

No files matched your search

+4
View File
@@ -754,6 +754,10 @@ func (fwd *fastDatapathForwarder) handleHeartbeatAck() {
} }
func (fwd *fastDatapathForwarder) Forward(key ForwardPacketKey) FlowOp { func (fwd *fastDatapathForwarder) Forward(key ForwardPacketKey) FlowOp {
if !key.SrcPeer.HasShortID || !key.DstPeer.HasShortID {
return nil
}
fwd.lock.RLock() fwd.lock.RLock()
defer fwd.lock.RUnlock() defer fwd.lock.RUnlock()
+2 -1
View File
@@ -68,7 +68,8 @@ type OverlayCrypto struct {
type OverlayForwarder interface { type OverlayForwarder interface {
// Forward a packet across the connection. May be called as // Forward a packet across the connection. May be called as
// soon as the forwarder is created, in particular before // soon as the forwarder is created, in particular before
// Confirm(). // Confirm(). The return value nil means the key could not be
// handled by this forwarder.
Forward(ForwardPacketKey) FlowOp Forward(ForwardPacketKey) FlowOp
// Confirm that the connection is really wanted, and so the // Confirm that the connection is really wanted, and so the
+37 -24
View File
@@ -124,8 +124,8 @@ type overlaySwitchForwarder struct {
lock sync.Mutex lock sync.Mutex
// the forwarder to send on // the index of the forwarder to send on
best OverlayForwarder best int
// the subsidiary forwarders // the subsidiary forwarders
forwarders []subForwarder forwarders []subForwarder
@@ -183,6 +183,7 @@ func (osw *OverlaySwitch) MakeForwarder(
fwd := &overlaySwitchForwarder{ fwd := &overlaySwitchForwarder{
remotePeer: params.RemotePeer, remotePeer: params.RemotePeer,
best: -1,
forwarders: make([]subForwarder, len(overlays)), forwarders: make([]subForwarder, len(overlays)),
stopChan: stopChan, stopChan: stopChan,
@@ -285,9 +286,6 @@ func (fwd *overlaySwitchForwarder) established(index int) {
fwd.forwarders[index].established = true fwd.forwarders[index].established = true
// less preferred forwarders are no longer needed
fwd.stopFrom(index + 1)
if !fwd.alreadyEstablished { if !fwd.alreadyEstablished {
fwd.alreadyEstablished = true fwd.alreadyEstablished = true
close(fwd.establishedChan) close(fwd.establishedChan)
@@ -323,7 +321,8 @@ func (fwd *overlaySwitchForwarder) stopFrom(index int) {
func (fwd *overlaySwitchForwarder) chooseBest() { func (fwd *overlaySwitchForwarder) chooseBest() {
// the most preferred established forwarder is the best // the most preferred established forwarder is the best
// otherwise, the most preferred working forwarder is the best // otherwise, the most preferred working forwarder is the best
var bestEstablished, bestWorking *subForwarder bestEstablished := -1
bestWorking := -1
for i := range fwd.forwarders { for i := range fwd.forwarders {
subFwd := &fwd.forwarders[i] subFwd := &fwd.forwarders[i]
@@ -331,18 +330,18 @@ func (fwd *overlaySwitchForwarder) chooseBest() {
continue continue
} }
if bestWorking == nil { if bestWorking < 0 {
bestWorking = subFwd bestWorking = i
} }
if bestEstablished == nil && subFwd.established { if bestEstablished < 0 && subFwd.established {
bestEstablished = subFwd bestEstablished = i
} }
} }
best := bestEstablished best := bestEstablished
if best == nil { if best < 0 {
if bestWorking == nil { if bestWorking < 0 {
select { select {
case fwd.errorChan <- fmt.Errorf("no working forwarders to %s", fwd.remotePeer): case fwd.errorChan <- fmt.Errorf("no working forwarders to %s", fwd.remotePeer):
default: default:
@@ -354,9 +353,10 @@ func (fwd *overlaySwitchForwarder) chooseBest() {
best = bestWorking best = bestWorking
} }
if fwd.best != best.fwd { if fwd.best != best {
fwd.best = best.fwd fwd.best = best
log.Info(fwd.logPrefix(), "using ", best.overlayName) log.Info(fwd.logPrefix(),
"using ", fwd.forwarders[best].overlayName)
} }
} }
@@ -378,14 +378,23 @@ func (fwd *overlaySwitchForwarder) Confirm() {
func (fwd *overlaySwitchForwarder) Forward(pk ForwardPacketKey) FlowOp { func (fwd *overlaySwitchForwarder) Forward(pk ForwardPacketKey) FlowOp {
fwd.lock.Lock() fwd.lock.Lock()
best := fwd.best
fwd.lock.Unlock()
if best == nil { if fwd.best >= 0 {
return nil for i := fwd.best; i < len(fwd.forwarders); i++ {
best := fwd.forwarders[i].fwd
if best != nil {
fwd.lock.Unlock()
if op := best.Forward(pk); op != nil {
return op
}
fwd.lock.Lock()
}
}
} }
return best.Forward(pk) fwd.lock.Unlock()
return DiscardingFlowOp{}
} }
func (fwd *overlaySwitchForwarder) EstablishedChannel() <-chan struct{} { func (fwd *overlaySwitchForwarder) EstablishedChannel() <-chan struct{} {
@@ -412,13 +421,17 @@ func (fwd *overlaySwitchForwarder) ControlMessage(tag byte, msg []byte) {
} }
func (fwd *overlaySwitchForwarder) DisplayName() string { func (fwd *overlaySwitchForwarder) DisplayName() string {
var best OverlayForwarder
fwd.lock.Lock() fwd.lock.Lock()
best := fwd.best if fwd.best > 0 {
best = fwd.forwarders[fwd.best].fwd
}
fwd.lock.Unlock() fwd.lock.Unlock()
if best == nil { if best != nil {
return "none" return best.DisplayName()
} }
return best.DisplayName() return "none"
} }