Changeset 245

Show
Ignore:
Timestamp:
04/04/08 04:24:15 (4 years ago)
Author:
ocmathew
Message:

Fix autoresetting protocols (Well, if after a PROTOCOL_ERROR it is okay to continue on a new track)

Location:
trunk/pyopencoin/oc
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk/pyopencoin/oc/entities.py

    r244 r245  
    734734 
    735735        >>> stt.send('FETCH_CDD_REQUEST', '0') 
    736         <Message('FETCH_CDD_PASS',[...]])> 
     736        <Message('FETCH_CDD_PASS',[...])> 
    737737 
    738738        >>> stt.send('foo') 
    739739        <Message('PROTOCOL_ERROR','send again...')> 
    740740 
    741         FIXME: There is a problem here. If we send anything other than a goodbye 
    742         next, we go into an infinite loop. I believe that the correct response is 
    743         another PROTOCOL_ERROR at this point 
    744         #>>> stt.send('FETCH_CDD_REQUEST', '0') 
    745         #<Message('FETCH_CDD_PASS',[...])> 
     741        >>> stt.send('FETCH_CDD_REQUEST', '0') 
     742        <Message('FETCH_CDD_PASS',[...])> 
    746743 
    747744        >>> stt.send('GOODBYE') 
     
    750747        """ 
    751748        if hasattr(transport, 'protocol') and transport.protocol: 
     749            # transport will only have protocol if we are looping on ourselves. Don't 
     750            # setup protocol again. Just reset the transport to use the protocol and 
     751            # reset the protocol itself 
    752752            transport.setProtocol(self.protocol) 
     753            self.protocol.newState(self.protocol.start)  
    753754 
    754755        else: 
  • trunk/pyopencoin/oc/protocols.py

    r244 r245  
    4949            message = Message('GOODBYE') 
    5050        #we are not done 
    51         if not self.done:                        
    52             #maybe we need to reset?                 
     51        if not self.done: 
     52            #maybe we need to reset? 
    5353            if message.type != 'GOODBYE' and hasattr(self, 'transport') and hasattr(self.transport, 'autoreset'): 
    5454                self.transport.autoreset(self.transport) 
     
    7171        self.state = method 
    7272         
    73     def initiateHandshake(self,message):    
     73    def initiateHandshake(self,message): 
    7474        self.newState(self.verifyHandshake) 
    7575        return Message('HANDSHAKE',[['protocol', 'opencoin 1.0']]) 
     
    176176            nextprotocol = self.mapping[message.type](self.arguments) 
    177177        except KeyError: 
    178             self.newState(self.goodbye) 
    179             return ProtocolErrorMessage('aHP') 
    180         except AttributeError: 
    181178            self.newState(self.goodbye) 
    182179            return ProtocolErrorMessage('aHP')