Show
Ignore:
Timestamp:
03/16/08 21:29:30 (4 years ago)
Author:
ocmathew
Message:

Change handshake options from a dict to key/value lists in a list.

Files:
1 modified

Legend:

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

    r211 r215  
    7272    def initiateHandshake(self,message):    
    7373        self.newState(self.verifyHandshake) 
    74         return Message('HANDSHAKE',{'protocol': 'opencoin 1.0'}) 
     74        return Message('HANDSHAKE',[['protocol', 'opencoin 1.0']]) 
    7575 
    7676    def verifyHandshake(self, message): 
    7777        if message.type == 'HANDSHAKE_ACCEPT': 
    7878            self.newState(self.firstStep) 
     79            # FIXME: If we have handshakes that return things, we need to check for them here 
    7980            return self.firstStep(message) 
    8081 
     
    101102    def start(self,message): 
    102103        if message.type == 'HANDSHAKE': 
    103             if message.data['protocol'] == 'opencoin 1.0': 
     104             
     105            # NOTE: We do not do set up the newState. If this fails, it comes right back to handshakes 
     106            if not isinstance(message.data, types.ListType): 
     107                return ProtocolErrorMessage('aHP') 
     108             
     109            for var in message.data: 
     110                try: 
     111                    key, value = var 
     112                except ValueError: 
     113                    return ProtocolErrorMessage('aHP') 
     114             
     115            if not message.data: 
     116                return ProtocolErrorMessage('aHP') 
     117 
     118            # Make a dictionary of options in the handshake 
     119 
     120            options = {} 
     121            for var in message.data: 
     122                key, value = var 
     123                if key in options: 
     124                    raise ProtocolErrorMessage('aHP') 
     125                 
     126                options[key] = value 
     127 
     128            # FIXME: If we allow opencoin 1.0+, we need to check for that as well 
     129            if options['protocol'] == 'opencoin 1.0': 
    104130                # Set up a state where the handshake no longer is needed. 
    105131                self.old_start = self.start 
     
    140166    >>> css = TokenSpendSender([coin1,coin2],'foobar') 
    141167    >>> css.state(Message(None)) 
    142     <Message('HANDSHAKE',{'protocol': 'opencoin 1.0'})> 
     168    <Message('HANDSHAKE',[['protocol', 'opencoin 1.0']])> 
    143169    >>> css.state(Message('HANDSHAKE_ACCEPT',None)) 
    144170    <Message('SUM_ANNOUNCE',['...', '3', 'foobar'])> 
     
    378404    >>> tts = TransferTokenSender('my account',[],[coin1, coin2],type='redeem') 
    379405    >>> tts.state(Message(None)) 
    380     <Message('HANDSHAKE',{'protocol': 'opencoin 1.0'})> 
     406    <Message('HANDSHAKE',[['protocol', 'opencoin 1.0']])> 
    381407    >>> tts.state(Message('HANDSHAKE_ACCEPT',None)) 
    382408    <Message('TRANSFER_TOKEN_REQUEST',['...', 'my account', [], [[(...)], [(...)]], [['type', 'redeem']]])> 
     
    874900    >>> fmp = fetchMintKeyProtocol(denominations=['1']) 
    875901    >>> fmp.state(Message(None)) 
    876     <Message('HANDSHAKE',{'protocol': 'opencoin 1.0'})> 
     902    <Message('HANDSHAKE',[['protocol', 'opencoin 1.0']])> 
    877903    >>> fmp.state(Message('HANDSHAKE_ACCEPT',None)) 
    878904    <Message('MINT_KEY_FETCH_DENOMINATION',[['1'], '0'])> 
     
    892918    >>> fmp = fetchMintKeyProtocol(keyids=['sj17RxE1hfO06+oTgBs9Z7xLut/3NN+nHJbXSJYTks0=']) 
    893919    >>> fmp.state(Message(None)) 
    894     <Message('HANDSHAKE',{'protocol': 'opencoin 1.0'})> 
     920    <Message('HANDSHAKE',[['protocol', 'opencoin 1.0']])> 
    895921    >>> fmp.state(Message('HANDSHAKE_ACCEPT')) 
    896922    <Message('MINT_KEY_FETCH_KEYID',['sj17RxE1hfO06+oTgBs9Z7xLut/3NN+nHJbXSJYTks0='])>