@@ -144,7 +144,7 @@ func DefaultExchangeSettings() *ExchangeSettings {
144144 ExchangeResidentWaitTimeout : exchangeResidentWaitTimeout ,
145145 ExchangeResidentPollTimeout : 15 * time .Second ,
146146
147- ForwardEnforceActiveContracts : false ,
147+ ForwardEnforceActiveContracts : true ,
148148
149149 ExchangeChaosSettings : * DefaultExchangeChaosSettings (),
150150 // default drain 300/minute
@@ -1583,37 +1583,36 @@ func (self *Resident) handleClientForward(path connect.TransferPath, transferFra
15831583
15841584 // FIXME deep packet inspection to look at the contract frames and verify contracts before forwarding
15851585
1586- if self .exchange .settings .ForwardEnforceActiveContracts {
1587- if ! isAck (transferFrameBytes ) {
1588- hasActiveContract := self .residentContractManager .HasActiveContract (sourceId , destinationId )
1589- if ! hasActiveContract {
1590- glog .Infof ("[rf]abuse no active contract %s->%s\n " , sourceId , destinationId )
1591- // there is no active contract
1592- // drop
1593- self .abuseLimiter .delay ()
1594- return
1595- }
1596- }
1597- }
1598-
15991586 c := func () bool {
16001587
16011588 nextForward := func () * ResidentForward {
1589+ if self .exchange .settings .ForwardEnforceActiveContracts {
1590+ // if !isAck(transferFrameBytes) {
1591+ hasActiveContract := self .residentContractManager .HasActiveContract (sourceId , destinationId )
1592+ if ! hasActiveContract {
1593+ glog .Infof ("[rf]abuse no active contract %s->%s\n " , sourceId , destinationId )
1594+ // there is no active contract
1595+ // drop
1596+ self .abuseLimiter .delay ()
1597+ return nil
1598+ }
1599+ // }
1600+ }
1601+
16021602 forward := NewResidentForward (self .ctx , self .exchange , destinationId )
16031603 go server .HandleError (func () {
1604- forward .Run ()
1605-
1606- glog .V (1 ).Infof ("[rf]close %s->%s\n " , sourceId , destinationId )
1607-
1608- // note we don't call close here because only the sender should call close
1609- forward .Cancel ()
1610- func () {
1604+ defer func () {
16111605 self .stateLock .Lock ()
16121606 defer self .stateLock .Unlock ()
1607+ forward .Cancel ()
16131608 if currentForward := self .forwards [destinationId ]; forward == currentForward {
16141609 delete (self .forwards , destinationId )
16151610 }
16161611 }()
1612+ forward .Run ()
1613+
1614+ glog .V (1 ).Infof ("[rf]close %s->%s\n " , sourceId , destinationId )
1615+ // note we don't call close here because only the sender should call close
16171616 }, forward .Cancel )
16181617 go server .HandleError (func () {
16191618 defer forward .Cancel ()
@@ -1670,6 +1669,10 @@ func (self *Resident) handleClientForward(path connect.TransferPath, transferFra
16701669 forward = nextForward ()
16711670 }
16721671
1672+ if forward == nil {
1673+ return false
1674+ }
1675+
16731676 select {
16741677 case <- self .ctx .Done ():
16751678 return false
0 commit comments