Exemplo n.º 1
0
    def signAndSend(self,
                    msg,
                    signingIdr=None,
                    toRaetStackName=None,
                    linkName=None,
                    origReqId=None):
        if linkName:
            assert not (signingIdr or toRaetStackName)
            link = self.wallet.getLink(linkName, required=True)
            if not link.localIdentifier:
                raise LinkNotReady('link is not yet established, '
                                   'send/accept invitation first')
            signingIdr = link.localIdentifier

            try:
                self.connectTo(link=link)
                ha = link.getRemoteEndpoint(required=True)
                params = dict(ha=ha)
            except RemoteEndpointNotFound as ex:
                logger.debug('ZStack remote found')
                if not (isinstance(self.endpoint, ZEndpoint) and self.endpoint.
                        hasRemote(link.remotePubKey.encode() if isinstance(
                            link.remotePubKey, str) else link.remotePubKey)):
                    fault(ex,
                          "Do not know {} {}".format(link.remotePubKey, ha))
                    return
            # TODO ensure status is appropriate with code like the following
            # if link.linkStatus != constant.LINK_STATUS_ACCEPTED:
            # raise LinkNotReady('link status is {}'.format(link.linkStatus))
                params = dict(name=link.remotePubKey)
        else:
            params = dict(name=toRaetStackName)
        # origReqId needs to be supplied when you want to respond to request
        # so that on receiving end, response can be matched with request
        # if origReqId:
        #     msg[f.REQ_ID.nm] = origReqId
        # else:
        #     msg[f.REQ_ID.nm] = getTimeBasedId()
        msg[f.REQ_ID.nm] = getTimeBasedId()
        if origReqId:
            msg[REF_REQUEST_ID] = origReqId

        msg[IDENTIFIER] = signingIdr
        signature = self.wallet.signMsg(msg, signingIdr)
        msg[f.SIG.nm] = signature
        self.sendMessage(msg, **params)
        return msg[f.REQ_ID.nm]
Exemplo n.º 2
0
    def signAndSendToLink(self, msg, linkName, origReqId=None):
        link = self.wallet.getLink(linkName, required=True)
        if not link.localIdentifier:
            raise LinkNotReady('link is not yet established, '
                               'send/accept invitation first')

        ha = link.getRemoteEndpoint(required=False)
        name = link.name
        if not ha:
            # if not remote address is present, then it's upcominh link, so we may have no
            # explicit connection (wrk in a listener mode).
            # PulicKey is used as a name in this case
            name = link.remotePubkey

        if ha:
            self.connectTo(link=link)

        return self.signAndSend(msg=msg, signingIdr=link.localIdentifier,
                                name=name, ha=ha, origReqId=origReqId)
Exemplo n.º 3
0
    def signAndSend(self,
                    msg,
                    signingIdr=None,
                    toRaetStackName=None,
                    linkName=None,
                    origReqId=None):
        if linkName:
            assert not (signingIdr or toRaetStackName)
            self.connectTo(linkName)
            link = self.wallet.getLink(linkName, required=True)
            ha = link.getRemoteEndpoint(required=True)

            # TODO ensure status is appropriate with code like the following
            # if link.linkStatus != constant.LINK_STATUS_ACCEPTED:
            #     raise LinkNotReady('link status is {}'.format(link.linkStatus))

            if not link.localIdentifier:
                raise LinkNotReady('local identifier not set up yet')
            signingIdr = link.localIdentifier
            params = dict(ha=ha)
        else:
            params = dict(name=toRaetStackName)
        # origReqId needs to be supplied when you want to respond to request
        # so that on receiving end, response can be matched with request
        # if origReqId:
        #     msg[f.REQ_ID.nm] = origReqId
        # else:
        #     msg[f.REQ_ID.nm] = getTimeBasedId()
        msg[f.REQ_ID.nm] = getTimeBasedId()
        if origReqId:
            msg[REF_REQUEST_ID] = origReqId

        msg[IDENTIFIER] = signingIdr
        signature = self.wallet.signMsg(msg, signingIdr)
        msg[f.SIG.nm] = signature
        self.sendMessage(msg, **params)
        return msg[f.REQ_ID.nm]