Пример #1
0
def CreatePeerProposalHeaderAndBody(peer, contractName, talkType, listenType,
                                    proposedRemoteQuota, proposedLocalQuota,
                                    hostName):
    """
    The CreatePeerProposalHeaderAndBody function creates a message
    to propose a contract to the peer.  All the inputs to this function
    are from the point of view of the peer we are proposing to.  For
    example, the talkType is what the peer would use as the argument
    to --talk and the proposedRemoteQuota is what the peer would use
    as the argument to --remote_quota in the add_peer function.

    """
    hdr = MakeMsgHeader(peer, 'DIBS CONTRACT PROPOSAL')

    pubKey = dibs_utils.RemovePGPHeaders(dibs_crypto.GetPubKey(),
                                         dibs_constants.pgpKeyStart,
                                         dibs_constants.pgpKeyEnd)

    body = MakeMsgCmd(
        dibs_constants.proposalCmdName,
        ((dibs_constants.contractNameArgName, contractName),
         (dibs_constants.adminArgName, dibs_options.dibsAdmin),
         (dibs_constants.talkTypeArgName, talkType),
         (dibs_constants.listenTypeArgName, listenType),
         (dibs_constants.remoteQuotaArgName, ` proposedRemoteQuota `),
         (dibs_constants.localQuotaArgName, ` proposedLocalQuota `),
         (dibs_constants.hostArgName, hostName),
         (dibs_constants.portArgName, ` dibs_options.daemonPort `),
         (dibs_constants.publicKeyNameArgName, dibs_options.dibsPublicKey),
         (dibs_constants.publicKeyArgName, pubKey)))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #2
0
def CreateForgetYouMsg(peer):
    hdr = MakeMsgHeader(peer, 'DIBS FORGET YOU')
    body = MakeMsgCmd(dibs_constants.forgetYouCmdName, ())

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #3
0
def CreateRecoverAllFinishedHdrAndBdy(peer):

    hdr = MakeMsgHeader(peer, 'DIBS FINISHED RECOVER ALL REQUEST')

    body = MakeMsgCmd(dibs_constants.doneRecoverAllCmdName, [])

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #4
0
def CreateClearDBHeaderAndBody(peer):

    hdr = MakeMsgHeader(peer, 'DIBS CLEAR REQUEST')

    body = MakeMsgCmd(dibs_constants.clearCmdName, ())

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #5
0
def CreateRecoverAllRequestHdrAndBdy(peer):

    hdr = MakeMsgHeader(peer, 'DIBS RECOVER ALL REQUEST')

    body = MakeMsgCmd(dibs_constants.recoverAllCmdName, [])

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #6
0
def CreateUnstoreHeaderAndBody(pieceName, peer):

    hdr = MakeMsgHeader(peer, 'DIBS UNSTORE REQUEST')

    body = MakeMsgCmd(dibs_constants.unstoreCmdName,
                      ((dibs_constants.pieceNameArgName, pieceName), ))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #7
0
def CreateRecoverRequestHeaderAndBody(pieceName, peer):

    hdr = MakeMsgHeader(peer, 'DIBS RECOVER REQUEST')

    body = MakeMsgCmd(dibs_constants.recoverCmdName,
                      ((dibs_constants.pieceNameArgName, pieceName), ))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #8
0
def CreateProbeRequestHeaderAndBody(pieceName, peer):

    hdr = MakeMsgHeader(peer, 'DIBS PROBE REQUEST')

    body = MakeMsgCmd(dibs_constants.probeCmdName,
                      ((dibs_constants.pieceNameArgName, pieceName), ))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #9
0
def CreateRecoverResponseHeaderAndBody(pieceName, peer, data):

    hdr = MakeMsgHeader(peer, 'DIBS RECOVER RESPONSE')

    body = MakeMsgCmd(
        dibs_constants.recoverResponseCmdName,
        ((dibs_constants.pieceNameArgName, pieceName),
         (dibs_constants.pieceDataArgName, dibs_utils.RemovePGPHeaders(data))))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #10
0
def CreateProposalResponseHeaderAndBody(peer, contractName, acceptedP,
                                        comment):
    hdr = MakeMsgHeader(peer, 'DIBS PROPOSAL RESPONSE')

    assert acceptedP == 'YES' or acceptedP == 'NO'

    body = MakeMsgCmd(dibs_constants.proposalResponseCmdName,
                      ((dibs_constants.contractNameArgName, contractName),
                       (dibs_constants.proposalDecisionArgName, acceptedP),
                       (dibs_constants.proposalCommentArgName, comment)))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)
Пример #11
0
def CreateStoreHeaderAndBody(peer, data, pieceName):
    """
    Prepare an email to peer requesting storage of 
    encryptedFile under the name pieceName.

    Returns header and body of email.
    """

    hdr = MakeMsgHeader(peer, 'DIBS STORE REQUEST')

    body = MakeMsgCmd(
        dibs_constants.storeCmdName,
        ((dibs_constants.pieceNameArgName, pieceName),
         (dibs_constants.pieceDataArgName, dibs_utils.RemovePGPHeaders(data))))

    body = dibs_crypto.SignPiece(body, peer)

    return (hdr, body)