How to use fcp - 10 common examples

To help you get started, we’ve selected a few fcp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github initc3 / HoneyBadgerBFT-Python / test / honest_party_test_Freenet.py View on Github external
def generateFreenetKeys(N):
    global publicKeys, nodeList
    mylog("Initiating ...")
    privateList = []
    USKPrivateList = []
    jobList = []
    for i in range(N * CONCURRENT_NUM):
        mylog("Registering node %d" % i)
        n = fcp.node.FCPNode()
        public, private = n.genkey()
        USKPublic, USKPrivate = n.genkey(name='badger', usk=True)
        mylog("Got public key %s, private key %s, USKPublic key %s, USKPrivate key %s" % (
            public, private, USKPublic, USKPrivate))
        mylog("Initializing msg_count for node %d" % i)
        # Set the initial counter
        j = n.put(uri=USKPrivate, data="0",
            mimetype="application/octet-stream", realtime=True, priority=0, async=True)
        jobList.append(j)
        # Update the lists
        publicKeys.append(public)
        USKPublicKeys.append(USKPublic)
        privateList.append(private)
        USKPrivateList.append(USKPrivate)
        nodeList.append(n)
    for index, job in enumerate(jobList):
github freenet / pyFreenet / freesitemgr.py View on Github external
def getChkCalcNode(addr):
    """
    yuck - using a separate node for chk calculation
    """
    parts = addr.split(":")
    nparts = len(parts)
    if nparts == 1:
        chkHost = addr
        chkPort = fcp.node.defaultFCPPort
    elif nparts == 2:
        chkHost = parts[0] or fcp.node.defaultFCPHost
        chkPort = parts[1] or fcp.node.defaultFCPPort
    
    try:
        chkNode = fcp.node.FCPNode(host=chkHost, port=chkPort)
        return chkNode
    except:
        return None
github freenet / pyFreenet / freesitemgr.py View on Github external
def getChkCalcNode(addr):
    """
    yuck - using a separate node for chk calculation
    """
    parts = addr.split(":")
    nparts = len(parts)
    if nparts == 1:
        chkHost = addr
        chkPort = fcp.node.defaultFCPPort
    elif nparts == 2:
        chkHost = parts[0] or fcp.node.defaultFCPHost
        chkPort = parts[1] or fcp.node.defaultFCPPort
    
    try:
        chkNode = fcp.node.FCPNode(host=chkHost, port=chkPort)
        return chkNode
    except:
        return None
github freenet / pyFreenet / fcp / genkey.py View on Github external
def main():
    """
    Front end for fcpget utility
    """

    parser = create_parser()
    args = parser.parse_args()

    # default job options
    verbosity = node.ERROR
    verbose = False

    # try to create the node
    try:
        fcp_node = node.FCPNode(host=args.fcphost, port=args.fcpport, verbosity=verbosity,
                         logfile=sys.stderr)
    except:
        if verbose:
            traceback.print_exc(file=sys.stderr)
        sys.stderr.write("Failed to connect to FCP service at %s:%d\n" % (args.fcphost, args.fcpport))
        sys.exit(1)

    # grab the keypair
    pub, priv = fcp_node.genkey()

    fcp_node.shutdown()

    # successful, return the uri
    print pub
    print priv
github freenet / pyFreenet / babcom.py View on Github external
>>> True
    True
    """
    import doctest
    tests = doctest.testmod()
    if tests.failed:
        return "☹"*tests.failed + " / " + numtostring(tests.attempted)
    return "^_^ (" + numtostring(tests.attempted) + ")"


if __name__ == "__main__":
    args = parse_args()
    slowtests = args.slowtests
    if args.port:
        fcp.node.defaultFCPPort = args.port
    if args.host:
        fcp.node.defaultFCPHost = args.host
    if args.verbosity:
        fcp.node.defaultVerbosity = int(args.verbosity)
    if args.test:
        print _test()
        sys.exit(0)
    prompt = Babcom()
    prompt.transient = args.transient
    prompt.username = args.user
    prompt.cmdloop('Starting babcom, type help or intro')
github freenet / pyFreenet / fcp / get.py View on Github external
args = parser.parse_args(argv)

    uri = args.key_uri
    if not uri.startswith("freenet:"):
        uri = "freenet:" + uri

    opts['priority'] = args.priority
    if args.global_queue:
        opts['Global'] = 'true'
    opts['persistence'] = args.persistence
    opts['timeout'] = args.timeout


    # try to create the node
    try:
        fcp_node = node.FCPNode(host=args.fcphost,
                         port=args.fcpport,
                         Global=args.global_queue,
                         verbosity=verbosity,
                         logfile=sys.stderr)
    except:
        if verbose:
            traceback.print_exc(file=sys.stderr)
        sys.stderr.write("Failed to connect to FCP service at %s:%s\n" % (args.fcphost, args.fcpport))
        sys.exit(1)

    # try to retrieve the key
    try:
        # print "opts=%s" % opts
        mimetype, data, msg = fcp_node.get(uri, **opts)
        fcp_node.shutdown()
    except:
github freenet / pyFreenet / fcp / node.py View on Github external
#    if uri.startswith("freenet:CHK@") or uri.startswith("CHK@"):
    #        uri = os.path.splitext(uri)[0]
    
        # process uri, including possible namesite lookups
        uri = uri.split("freenet:")[-1]
        if len(uri) < 5 or (uri[:4] not in ('SSK@', 'KSK@', 'CHK@', 'USK@', 'SVK@')):
            # we seem to have a 'domain name' uri
            try:
                domain, rest = uri.split("/", 1)
            except:
                domain = uri
                rest = ''
            
            tgtUri = self.namesiteLookup(domain)
            if not tgtUri:
                raise FCPNameLookupFailure(
                        "Failed to resolve freenet domain '%s'" % domain)
            if rest:
                uri = (tgtUri + "/" + rest).replace("//", "/")
            else:
                uri = tgtUri
            
        opts['URI'] = uri
    
        opts['MaxRetries'] = kw.get("maxretries", -1)
        opts['MaxSize'] = kw.get("maxsize", "1000000000000")
        opts['PriorityClass'] = int(kw.get("priority", 1))
    
        opts['timeout'] = int(kw.pop("timeout", ONE_YEAR))
    
        #print "get: opts=%s" % opts
github freenet / pyFreenet / fcp / node.py View on Github external
if opts['Global'] == 'true' and opts['Persistence'] == 'connection':
            raise Exception("Global requests must be persistent")
    
        # process uri, including possible namesite lookups
        uri = uri.split("freenet:")[-1]
        if len(uri) < 4 or (uri[:4] not in ('SSK@', 'KSK@', 'CHK@', 'USK@', 'SVK@')):
            # we seem to have a 'domain name' uri
            try:
                domain, rest = uri.split("/", 1)
            except:
                domain = uri
                rest = ''
            
            tgtUri = self.namesiteLookup(domain)
            if not tgtUri:
                raise FCPNameLookupFailure(
                        "Failed to resolve freenet domain '%s'" % domain)
            if rest:
                uri = (tgtUri + "/" + rest).replace("//", "/")
            else:
                uri = tgtUri
    
        opts['URI'] = uri
        
        # determine a mimetype
        mimetype = kw.get("mimetype", None)
        if kw.has_key('mimetype'):
            # got an explicit mimetype - use it
            mimetype = kw['mimetype']
        else:
            # not explicitly given - figure one out
            ext = os.path.splitext(uri)[1]
github freenet / pyFreenet / freesitemgr.py View on Github external
def getChkCalcNode(addr):
    """
    yuck - using a separate node for chk calculation
    """
    parts = addr.split(":")
    nparts = len(parts)
    if nparts == 1:
        chkHost = addr
        chkPort = fcp.node.defaultFCPPort
    elif nparts == 2:
        chkHost = parts[0] or fcp.node.defaultFCPHost
        chkPort = parts[1] or fcp.node.defaultFCPPort
    
    try:
        chkNode = fcp.node.FCPNode(host=chkHost, port=chkPort)
        return chkNode
    except:
        return None
github freenet / pyFreenet / freesitemgr.py View on Github external
def getChkCalcNode(addr):
    """
    yuck - using a separate node for chk calculation
    """
    parts = addr.split(":")
    nparts = len(parts)
    if nparts == 1:
        chkHost = addr
        chkPort = fcp.node.defaultFCPPort
    elif nparts == 2:
        chkHost = parts[0] or fcp.node.defaultFCPHost
        chkPort = parts[1] or fcp.node.defaultFCPPort
    
    try:
        chkNode = fcp.node.FCPNode(host=chkHost, port=chkPort)
        return chkNode
    except:
        return None