def initialize_Bazaar(port):
        gpg_which = which('gpg')
        if gpg_which == None:
            print "You do not have gpg installed. Please install gpg using \'sudo apt-get install gpg\' or some alternative."
            exit()
        else:
            ##
            #  Generate the gpg key in the identity directory,
            #  export the armored key, create a GUID
            #

            gpg = BazaarInit.gen_keys(gpg_which)
            pub_key_armor = gpg.export_keys(gpg.list_keys()[0]['keyid'])
            priv_key_armor = gpg.export_keys(gpg.list_keys()[0]['keyid'], secret=True)
            guid = BazaarInit.create_GUID(str(gpg.sign(pub_key_armor, binary=True)))

            ##
            #  Create Node object
            #
            node = OBNode(guid, port)

            ##
            # Create Identity module
            #
            id_mod = Identity(guid, pub_key_armor, priv_key_armor, gpg)

            ##
            # Dump state of id and node objects for future retrieval.
            #
            id_mod.save()
            node.saveState()
    def read_config(self, path):
        path = path.split('.').pop(0).split('/').pop()
        confmod = __import__(path)
        self.identity = Identity()
        if not self.identity.load_identity(confmod.conf['identity']):
            return False
        
        self.connections = []
        
        for connection in confmod.conf['connections']:
            plugins = []
            # XXX Validate existance of connections.plugins
            for plugin_config in connection.get('plugins', []):
                if not plugin_config.get('module'):
                    continue
                filename = plugin_config['module']
                try:
                    name = filename.rsplit('.')[0]
                except (IndexError, ValueError):
                    logging.warn('Invalid module filename \'%s\'' % filename)
                else:
                    module = __import__(name)
                    plugins.append((module, plugin_config))

            connection['plugins'] = plugins
            self.connections.append(connection)
        return True
示例#3
0
文件: orm.py 项目: kball/ambry
    def set_ids(self, sequence_id):
        from identity import Identity

        self.sequence_id = sequence_id

        don = ObjectNumber.parse(self.d_vid)
        pon = PartitionNumber(don, self.sequence_id)

        self.vid = str(pon)
        self.id_ = str(pon.rev(None))
        self.fqname = Identity._compose_fqname(self.vname,self.vid)
示例#4
0
 def Put(cls, userId, content, roomId):
     room = Room.Get(roomId)
     user = Identity.Get(userId)
     if room and user:
         message = Message(User=user,
                           Content=content,
                           Room=room,
                           Id=uuid4().hex)
         message.put()
         return message
     return None
示例#5
0
文件: node.py 项目: smashnet/SmashDHT
 def __init__(self, mylog, myIdentity=None, netAccess=None):
     self.smashlog = mylog
     
     if myIdentity is None:
         self.identity = Identity(mylog)
     else:
         self.identity = myIdentity
         
     if netAccess is None:
         self.net = Network(mylog)
     else:
         self.net = netAccess
示例#6
0
def manage(req):
    from identity import Identity
    import commvals
    import status
    import hashlib

    s = status.Status()
    t = Identity()
    resp = dict()
    if req.POST:
        passwd = req.POST.get('password')
        if hashlib.md5(passwd.encode('utf-8')).hexdigest() == commvals.SERVER_PASSWORD:
            t.ids.append(req.META.get('REMOTE_ADDR'))
            resp.update({'identity': True})
        else:
            resp.update({'identity': False})
    else:
        if t.identity(req.META.get('REMOTE_ADDR')):
            resp.update({'identity': True})
        else:
            resp.update({'identity': False})
    return render_to_response('manage.html', resp)
示例#7
0
文件: node.py 项目: smashnet/SmashDHT
class Node():
    def __init__(self, mylog, myIdentity=None, netAccess=None):
        self.smashlog = mylog
        
        if myIdentity is None:
            self.identity = Identity(mylog)
        else:
            self.identity = myIdentity
            
        if netAccess is None:
            self.net = Network(mylog)
        else:
            self.net = netAccess
        
    def __str__(self):
        res = "\n---Node Information---\n"
        res += str(self.identity) + "\n"
        res += str(self.net) + "\n"
        res += "----------------------"
        return res
        
    def run(self):
        # Booting up network
        self.smashlog.log(1,"Booting up network for node %s" % self.identity.getID())
        if(self.net.startNetwork()):
            self.smashlog.log(3, "Error starting server for node %s" % self.identity.getID())
            return -1
        
        self.smashlog.log(1,"Node %s is up:\n%s" % (self.identity.getID(), str(self.net)))

        try:
            while True:
                self.net.listenForNewConnections()
                time.sleep(0.05)
        except KeyboardInterrupt:
            self.net.cleanup()
            self.smashlog.log(1, "Caught user interrupt! Shutting down node %s" % self.identity.getID())
            self.smashlog.close()
示例#8
0
    def __init__(self):
        self.config = config
        self.identity = Identity()
        self.ipfs = IPFSNode()
        self.scandb = ScanDB(
            self.ipfs,
            self.identity,
            self.config['main']['username'],
            index_path='scandb/index_dag',
            data_path='scandb/data_blocks',
            write_buffer_path='/data/filestore/scandb/buffer.json',
            heads_file_path='/data/filestore/scandb/dag_heads.json',
            genesis_nodes=self.config['scandb']['genesis_nodes'],
            logger_name='SCANDB',
            log_level=self.config['scandb']['log_level'],
        )

        self.status = {}
        self.scanner = PortScanner()
        self.scan_queue = queue.Queue()

        self.logger = get_logger('MAIN', self.config['main']['log_level'])

        self.consumer_queue = queue.Queue()
        self.producer_queue = queue.Queue()

        self.status = {
            'scandb': {
                'index_dag': {
                    'sync': True
                },
                'data_blocks': {
                    'sync': True,
                    'total': 0,
                    'pending': 0
                }
            },
            'port_scanner': {
                'mode': 'scan',  # banner_grab or analysis
                'data': {}
            },
            'ipfs': {
                'pubsub_peers': 0,
                'swarm_peers': 0
            }
        }
示例#9
0
 def creatorcode(self):
     from identity import Identity
     return Identity._creatorcode(self)
示例#10
0
文件: orm.py 项目: kball/ambry
 def identity(self):
     from identity import Identity
     return Identity.from_dict(self.dict )
示例#11
0
    def __init__(self):

        self.merchant_data = list()
        self.notary_data = list()

        gpg_which = InitializationMod.which('gpg')
        gpg = InitializationMod.BazaarInit.gen_keys(gpg_which)
        pub_key_armor = gpg.export_keys(gpg.list_keys()[0]['keyid'])
        priv_key_armor = gpg.export_keys(gpg.list_keys()[0]['keyid'],
                                         secret=True)
        guid = InitializationMod.BazaarInit.create_GUID(
            str(gpg.sign(pub_key_armor, binary=True)))

        #Code to create a merchant
        #merchant dictionary
        merch_dict = dict()
        merch_dict2 = dict()
        merch_dict3 = dict()
        merch_dict4 = dict()

        #listing dictionary
        listing_dict = dict()
        listing_dict2 = dict()
        listing_dict3 = dict()
        listing_dict4 = dict()
        listing_dict5 = dict()
        listing_dict6 = dict()

        #listings for merchant 1
        listing_dict['expiry'] = "12/25/15"
        listing_dict['price'] = "1000"
        listing_dict['bitcoin_address'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        listing_dict[
            'item_name'] = "Custom Computer Intel Core i7, 16GB Ram, 3TB"
        listing_dict[
            'keywords'] = "custom, computer, liquidcooling, used, intel, core, i7"
        listing_dict[
            'description'] = "Slightly used custom built gaming computer. Specs are as follows: Intel Core i7 4770K, 16GB Ram, 3TB, 240GB SSD, GTX 760ti"
        listing_dict['images'] = list()

        #add image to listing
        listing_dict['images'].append(DemoDataStrings.computer)

        #listings for merchant 2
        listing_dict2['expiry'] = "12/25/16"
        listing_dict2['price'] = "50"
        listing_dict2['bitcoin_address'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        listing_dict2['item_name'] = "Cleveland Indians Fitted (7 1/2)"
        listing_dict2[
            'keywords'] = "fiftyninefifty,fitted,lids,mlb,baseball,hat"
        listing_dict2['description'] = "Cleveland Inidians Original MLB Fitted"
        listing_dict2['images'] = list()

        #add image to listing
        listing_dict2['images'].append(DemoDataStrings.cleveland)

        #listings for merchant 3
        listing_dict3['expiry'] = "12/25/16"
        listing_dict3['price'] = "1000"
        listing_dict3['bitcoin_address'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        listing_dict3['item_name'] = "1/2 Carat Diamond Ring"
        listing_dict3['keywords'] = "ring,carat,diamond,gift,wedding"
        listing_dict3[
            'description'] = "1/2 carat diamond ring, beautiful clarity, incredible sparkle, your significant other will adore you!"
        listing_dict3['images'] = list()

        #add image to listing
        listing_dict3['images'].append(DemoDataStrings.ring)

        listing_dict4['expiry'] = "12/25/15"
        listing_dict4['price'] = "10000"
        listing_dict4['bitcoin_address'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        listing_dict4['item_name'] = "1 Carat Diamond Necklace"
        listing_dict4['keywords'] = "necklace,carat,diamond,gift,beautiful"
        listing_dict4[
            'description'] = "Diamond necklace perfect for that special somebody!"
        listing_dict4['images'] = list()

        #add image to listing
        listing_dict4['images'].append(DemoDataStrings.necklace)

        #listings for merchant 4
        listing_dict5['expiry'] = "12/25/15"
        listing_dict5['price'] = "100"
        listing_dict5['bitcoin_address'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        listing_dict5[
            'item_name'] = "PVL Iso-Gold Premium Isolated Whey Protein *Exclusive Bonus Size!*, 6 lbs"
        listing_dict5['keywords'] = "protein,whey,gold,premium"
        listing_dict5[
            'description'] = "PVL has always been a manufacturer of superior protein products, and the new 2012 formula of Iso-Gold exceeds expectations. Using the latest research this formula improves on their already premier formula, you can expect to see the extra features help boost your immune system and digest the protein even easier. Taking Iso-Gold before or after training will excel your recovery rate and improve on building muscles."
        listing_dict5['images'] = list()

        #add image to listing
        listing_dict5['images'].append(DemoDataStrings.protienfront)
        listing_dict5['images'].append(DemoDataStrings.protienback)

        #listings for merchant 4atman
        listing_dict6['expiry'] = "12/25/15"
        listing_dict6['price'] = "50"
        listing_dict6['bitcoin_address'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        listing_dict6[
            'item_name'] = "BSN N.O.-XPLODE *Exclusive Bonus Size*, 999 Grams"
        listing_dict6['keywords'] = "preworkout,energy,noxplode"
        listing_dict6[
            'description'] = "The Original Pre-Workout Igniter. Re-engineered."
        listing_dict6['images'] = list()

        #add image to listing
        listing_dict6['images'].append(DemoDataStrings.prefront)
        listing_dict6['images'].append(DemoDataStrings.preback)

        merch_dict['guid'] = guid
        merch_dict['pubkey'] = pub_key_armor
        merch_dict['email'] = "*****@*****.**"
        merch_dict['nickname'] = "DanuelGinobli"
        merch_dict[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        merch_dict[
            'storeDescription'] = "The best computer wholesaler on the OpenBazaar"
        merch_dict['myListings'] = [
            identity.RicardianContract(listing_dict, merch_dict, guid,
                                       pub_key_armor)
        ]
        merch_dict['avatar'] = ImageStorage(DemoDataStrings.danny_profile)

        merch_dict2['guid'] = guid
        merch_dict2['pubkey'] = pub_key_armor
        merch_dict2['email'] = "*****@*****.**"
        merch_dict2['nickname'] = "The Hat Man"
        merch_dict2[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        merch_dict2[
            'storeDescription'] = "The best fitted hat wholesaler on the OpenBazaar"
        merch_dict2['myListings'] = [
            identity.RicardianContract(listing_dict2, merch_dict2, guid,
                                       pub_key_armor)
        ]
        merch_dict2['avatar'] = ImageStorage(DemoDataStrings.hatman)

        merch_dict3['guid'] = guid
        merch_dict3['pubkey'] = pub_key_armor
        merch_dict3['email'] = "*****@*****.**"
        merch_dict3['nickname'] = "Marilyn's Jewellery"
        merch_dict3[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        merch_dict3[
            'storeDescription'] = "The hottest diamonds on the OpenBazaar"
        merch_dict3['myListings'] = [
            identity.RicardianContract(listing_dict3, merch_dict3, guid,
                                       pub_key_armor),
            identity.RicardianContract(listing_dict4, merch_dict3, guid,
                                       pub_key_armor)
        ]
        merch_dict3['avatar'] = ImageStorage(DemoDataStrings.marlyn)

        merch_dict4['guid'] = guid
        merch_dict4['pubkey'] = pub_key_armor
        merch_dict4['email'] = "*****@*****.**"
        merch_dict4['nickname'] = "Popeye's Supplement Store"
        merch_dict4[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        merch_dict4['storeDescription'] = "Supplements Lowest Prices!"
        merch_dict4['myListings'] = [
            identity.RicardianContract(listing_dict5, merch_dict4, guid,
                                       pub_key_armor),
            identity.RicardianContract(listing_dict6, merch_dict4, guid,
                                       pub_key_armor)
        ]
        merch_dict4['avatar'] = ImageStorage(DemoDataStrings.popeye)

        self.merchant_data.append(identity.Merchant(merch_dict4))
        self.merchant_data.append(identity.Merchant(merch_dict3))
        self.merchant_data.append(identity.Merchant(merch_dict2))
        self.merchant_data.append(identity.Merchant(merch_dict))

        #code to create a notary
        #give notary instance to DemoData

        #create an empty dict and populate fields with notary data
        notary_dict = dict()
        notary_dict['pubkey'] = pub_key_armor
        notary_dict['fee'] = "0.5"
        notary_dict['name'] = "Marilyn's Jewellery"
        notary_dict['guid'] = guid
        notary_dict[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        notary_dict['email'] = "*****@*****.**"
        notary_dict['description'] = "The Hottest Service"
        notary_dict['avatar'] = ImageStorage(DemoDataStrings.marlyn)

        notary_dict1 = dict()
        notary_dict1['pubkey'] = pub_key_armor
        notary_dict1['fee'] = "0.25"
        notary_dict1['name'] = "DanuelGinobli"
        notary_dict1['guid'] = guid
        notary_dict1[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        notary_dict1['email'] = "*****@*****.**"
        notary_dict1[
            'description'] = "Standard notarization services, great service, fair prices!"
        notary_dict1['avatar'] = ImageStorage(DemoDataStrings.danny_profile)

        notary_dict2 = dict()
        notary_dict2['pubkey'] = pub_key_armor
        notary_dict2['fee'] = "0.1"
        notary_dict2['name'] = "Popeye's Supplement Store"
        notary_dict2['guid'] = guid
        notary_dict2[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        notary_dict2['email'] = "*****@*****.**"
        notary_dict2['description'] = "The strongest service in town"
        notary_dict2['avatar'] = ImageStorage(DemoDataStrings.popeye)

        notary_dict3 = dict()
        notary_dict3['pubkey'] = pub_key_armor
        notary_dict3['fee'] = "free"
        notary_dict3['name'] = "The Hat Man"
        notary_dict3['guid'] = guid
        notary_dict3[
            'bitcoinReceivingAddress'] = "19PhnZCxayeitE3D3SjWWJ3QbN9UEU2mMV"
        notary_dict3['email'] = "*****@*****.**"
        notary_dict3[
            'description'] = "Standard notarization services, great service, fair prices!"
        notary_dict3['avatar'] = ImageStorage(DemoDataStrings.hatman)

        #now set the notary settings
        self.notary_data.append(identity.NotaryRepresentation(notary_dict))
        self.notary_data.append(identity.NotaryRepresentation(notary_dict1))
        self.notary_data.append(identity.NotaryRepresentation(notary_dict2))
        self.notary_data.append(identity.NotaryRepresentation(notary_dict3))
def identity():
    from identity import Identity
    return Identity("*****@*****.**", [
        "rsa",
        "-----BEGIN RSA PRIVATE KEY-----\nMIICXAIBAAKBgQDAZQNip0GPxFZsyxcgIgyvuPTHsruu66DBsESG5/Pfbcye3g4W\nwfg+dBP3IfUnLB4QXGzK42BAd57fCBXOtalSOkFoze/C2q74gYFBMvIPbEfef8yQ\n83uoNkYAFBVp6yNlT51IQ2mY19KpqoyxMZftxwdtImthE5UG1knZE64sIwIDAQAB\nAoGAIGjjyRqj0LQiWvFbU+5odLGTipBxTWYkDnzDDnbEfj7g2WJOvUavqtWjB16R\nDahA6ECpkwP6kuGTwb567fdsLkLApwwqAtpjcu96lJpbRC1nq1zZjwNB+ywssqfV\nV3R2/rgIEE6hsWS1wBHufJeqBZtlkeUp/VEx/uopyuR/WgECQQDJOaFSutj1q1dt\nNO23Q6w3Ie4uMQ59rWeRxXA5+KjDZCxrizzo/Bew5ZysJzHB2n8QQ15WJ7gTSjwJ\nMQdl/7SJAkEA9MQG/6JivkhUNh45xMYqnMHuutyIeGE17QndSfknU+8CX9UBLjsL\nw1QU+llJ3iYfMPEDaydn0HJ8+iinyyAISwJAe7Z2vEorwT5KTdXQoG92nZ66tKNs\naVAG8NQWH04FU7tuo9/C3uq+Ff/UxvKB4NDYdcM1aHqa7SEir/P4vHjtIQJAFKc9\n1/BB2MCNqoteYIZALj4HAOl+8nlxbXD5pTZK5UAzuRZmJRqCYZcEtiM2onIhC6Yq\nna4Tink+pnUrw24OhQJBAIjujQS5qwOf2p5yOqU3UYsBv7PS8IitmYFARTlcYh1G\nrmcIPHRtkxIwNuFxy3ZRRPEDGFa82id5QHUJT8sJbqY=\n-----END RSA PRIVATE KEY-----"
    ], ['local', None, 'mitzi'])
示例#13
0
            with open(self.heads_file_path, 'r') as f:
                data = json.load(f)
                self.sync_index_dag(data, pin=True)
        except FileNotFoundError:
            pass

        if self.sync_data_blocks:
            self.start_data_blocks_sync()
        Thread(target=self.sync_index_dag_loop).start()
        Thread(target=self.send_pings).start()
        Thread(target=self.generate_nodes).start()

        for msg in self.ipfs.run():
            self.process_pubsub_msg(msg)


if __name__ == '__main__':
    from config import config
    from ipfs import IPFSNode
    from identity import Identity
    db = DAGDB(IPFSNode(),
               Identity(),
               config['main']['username'],
               index_path='scandb/index_dag',
               data_path='scandb/data_blocks',
               write_buffer_path='/data/filestore/scandb/buffer.json',
               heads_file_path='/data/filestore/scandb/dag_heads.json',
               genesis_nodes=config['scandb']['genesis_nodes'],
               log_level='DEBUG')
    db.run()
示例#14
0
from flask import Flask, request, render_template
from werkzeug.datastructures import CombinedMultiDict
from werkzeug.utils import secure_filename

from config import Config
from identity import Identity
from identity_form import IdentityForm

import requests

app = Flask(__name__)
app.config[
    "SECRET_KEY"] = "ADn4fgcR1o89tpKRnfuIVRmQUHBsBkRKMpcC8EqAkNkilnDZ42HlNj"
# app.config['UPLOAD_FOLDER'] = "/tmp"
identitier = Identity()


@app.route("/page")
def page():
    return render_template('page.html')


@app.route("/identity", methods=['GET', 'POST'])
def identity():
    form = IdentityForm(CombinedMultiDict([request.form, request.files]))

    if Config.secret is not None and Config.secret != form.secret:
        return {'errno': 1003, 'errmsg': 'secret error.'}

    file_type = form.file_type.data
示例#15
0
from identity import Identity

print( Identity(2).map(lambda x: x**3).extract() )
print( Identity(lambda x: x**3).apply(Identity(2)).extract() )
print( Identity.of(8).extract() )
print( Identity.of(2).chain(lambda x: Identity(x**3)).extract() )

class AdditiveGroup:
    def __init__(self, value):
        self.value = value

    def empty(self):
        return AdditiveGroup(0)

    def concat(self, group):
        return AdditiveGroup(self.value + group.value)

    def extract(self):
        return self.value

print ( Identity(AdditiveGroup(0)).empty().concat(Identity(AdditiveGroup(8))).extract().extract() )
示例#16
0
'''

# Set configuration for labelled dataset
labelled_options = SetOptions(
    'Datasets/Kaggle/titanic/train.csv',
    'Results/Kaggle/titanic/plots/train',
    'Parquets/Kaggle/titanic/train', {
        'train': 0.5,
        'test': 0.3,
        'ver': 0.2
    }, [
        'PassengerId', 'Survived', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp',
        'Parch', 'Ticket', 'Fare', 'Cabin', 'Embarked'
    ],
    Identity(
        1, 'Labelled training, testing and verification sets for Titanic data',
        'titanic-labelled'),
    shuffle=False,
    random_state=1,
    persist=False)

# Set configuration for unlabelled dataset
unlabelled_options = SetOptions(
    'Datasets/Kaggle/titanic/test.csv',
    'Results/Kaggle/titanic/plots/test',
    'Parquets/Kaggle/titanic/test', {'data': 1.0}, [
        'PassengerId', 'Pclass', 'Name', 'Sex', 'Age', 'SibSp', 'Parch',
        'Ticket', 'Fare', 'Cabin', 'Embarked'
    ],
    Identity(2, 'Unlabelled test data for Titanic data', 'titanic-unlabelled'),
    shuffle=False,