@@ -431,6 +431,7 @@ func (px *proxifier) removeProxy(id string, force bool) bool {
431431 }
432432 core .Go ("pxr.removeProxy: " + id , func () {
433433 px .unmapHopFrom (p , false /*dryrun*/ )
434+
434435 _ = p .Stop ()
435436 if ! perma {
436437 px .obs .OnProxyRemoved (x .StrOf (id ))
@@ -795,10 +796,6 @@ func (px *proxifier) hop(via, origin string, dryrun bool) error {
795796}
796797
797798func (px * proxifier ) mapHop (hop x.Proxy , orig x.Proxy , dryrun bool ) (mapped bool ) {
798- if dryrun {
799- return
800- }
801-
802799 hopID := idstr (hop )
803800 origID := idstr (orig )
804801 if len (hopID ) <= 0 || len (origID ) <= 0 {
@@ -807,8 +804,13 @@ func (px *proxifier) mapHop(hop x.Proxy, orig x.Proxy, dryrun bool) (mapped bool
807804
808805 px .hmu .Lock ()
809806 defer px .hmu .Unlock ()
810- px .hp [hopID ] = addElem (px .hp [hopID ], origID )
811- return true
807+ in := px .hp [hopID ] // in may be nil
808+ out := addElem (in , origID )
809+ if ! dryrun {
810+ px .hp [hopID ] = out
811+ }
812+ log .I ("proxy: mapHop: %s => %s; remaining origins: %v" , hopID , origID , out )
813+ return len (out ) > len (in )
812814}
813815
814816func (px * proxifier ) unmapHopFrom (orig x.Proxy , dryrun bool ) (unmapped bool ) {
@@ -817,10 +819,6 @@ func (px *proxifier) unmapHopFrom(orig x.Proxy, dryrun bool) (unmapped bool) {
817819}
818820
819821func (px * proxifier ) unmapHop (hop x.Proxy , orig x.Proxy , dryrun bool ) (unmapped bool ) {
820- if dryrun {
821- return
822- }
823-
824822 hopID := idstr (hop )
825823 origID := idstr (orig )
826824 if len (hopID ) <= 0 || len (origID ) <= 0 {
@@ -832,7 +830,15 @@ func (px *proxifier) unmapHop(hop x.Proxy, orig x.Proxy, dryrun bool) (unmapped
832830
833831 if in , ok := px .hp [hopID ]; ok {
834832 out := removeElem (in , origID )
835- px .hp [hopID ] = out
833+ if ! dryrun {
834+ if len (out ) <= 0 {
835+ log .I ("proxy: unmapHop: %s => %s; no more origins, removing hop" , hopID , origID )
836+ delete (px .hp , hopID ) // remove hop if no origins left
837+ } else {
838+ log .I ("proxy: unmapHop: %s => %s; remaining origins: %v" , hopID , origID , out )
839+ px .hp [hopID ] = out
840+ }
841+ }
836842 unmapped = len (out ) < len (in )
837843 }
838844 return
0 commit comments