コード例 #1
0
ファイル: quantum.py プロジェクト: f-prime/QuantumCoin
 def main(self):
     if not os.path.exists("nodes.db"):
         self.db = landerdb.Connect("nodes.db")
         self.get_nodes()
         self.send_checkin()
     self.db = landerdb.Connect("nodes.db")
     self.sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
     self.sock.bind(("0.0.0.0", self.port))
     self.sock.listen(5)
     while True:
         obj, conn = self.sock.accept()
         threading.Thread(target=self.handle, args=(obj, conn)).start()
コード例 #2
0
def difficulty():
    coins = landerdb.Connect("coins.db")
    coins = coins.find("coins", "all")
    if coins:
        return len(coins) / 205000 + 7
    if not coins:
        return 7
コード例 #3
0
class SM(cmd.Cmd):
    prompt = "> "
    intro = "Type `help` for a list of commands"
    global db
    db = landerdb.Connect("/home/frankie/Dropbox/Python_Projects/ServerManager/servers.db")
    
    def do_help(self, line):
        print """


            servers - Lists servers and their passwords
            add <ip> <password> <descrition>
            connect <username> <number>
            edit <number> <password>
            delete <number> 

        """

    def do_servers(self, line):
        data = db.find("servers", "all")
        for num, x in enumerate(data):
            print str(num)+") "+x['ip'], x['password'], x['description']

    def do_add(self, line):
        line = line.split()
        db.insert("servers",{"ip":line[0], "password":line[1], "description":' '.join(line[2:])})
        db.save()
    
    def do_connect(self, line):
        out = db.find("servers", "all")
        line = line.split()
        password = out[int(line[1])]['password']
        ip = out[int(line[1])]['ip']
        ssh = "sshpass -p {0} ssh {1}@{2}".format(password, line[0], ip)
        os.system(ssh)

    def do_edit(self, line):
        line = line.split()
        all_ = db.find("servers", "all")
        all_ = all_[int(line[0])]
        db.update("servers", all_, {"password":line[1]})
        db.save()

    def do_delete(self, line):
        line = line.split()
        check = db.find("servers", "all")
        db.remove("servers", check[int(line[0])])
        db.save()
コード例 #4
0
def check(data, obj, conn):
    """{"cmd":"check", "addr":str, "hash":str, "plain":str}"""
    coins = landerdb.Connect("coins.db")
    coins = coins.find("coins", "all")
    check = sha512(data['plain']).hexdigest() == data['hash']
    exists = False
    exist = {"addr": data['addr'], 'hash': data['hash']}
    if exist in coins:
        exists = True
    if not exists and check:
        if data['hash'].startswith("1" * difficulty()):
            coins.insert({"addr": data['addr'], "hash": data['hash']})
            obj.send(json.dumps({"message": "Success"}))
        else:
            obj.send(json.dumps({"message": "Failed"}))
    else:
        obj.send(json.dumps({"message": "Failed"}))

    obj.close()
コード例 #5
0
ファイル: quantum.py プロジェクト: f-prime/QuantumCoin
 def get_nodes(self):
     sock = socket.socket()
     sock.connect(self.broker)
     with open("nodes.db", 'wb') as file:
         db = landerdb.Connect("wallet.db")
         addr = db.find("data", "all")[0]
         for x in addr:
             addr = x
             break
         data = {"addr":addr}
         sock.send(json.dumps(data))
         while True:
             get = sock.recv(1024)
             if get:
                 file.write(get)
             else:
                 break
     sock.close()
     print "Downloaded Nodes"
コード例 #6
0
ファイル: quantum.py プロジェクト: f-prime/QuantumCoin
 def send_checkin(self):
     nodes = self.db.find("nodes", "all")
     addr = landerdb.Connect("wallet.db")
     addr_ = addr.find("data", "all")[0]
     addr = ""
     for x in addr_:
         addr = x
     for x in nodes:
         s = socket.socket()
         ip = None
         port = None
         for y in x:
             ip = y
             port = 5554
             break
         try:
             s.settimeout(1)
             s.connect((ip, int(port)))
             s.send(json.dumps({"cmd":"checkin", "addr":addr}))
         except Exception, error:
             s.close()
             continue
         s.close()
コード例 #7
0
ファイル: broker.py プロジェクト: f-prime/ByteMail
 def __init__(self):
     self.port = 4321
     self.db = landerdb.Connect("nodes.db")
コード例 #8
0
ファイル: config.py プロジェクト: zonedoutspace/ShaCoin
import landerdb

relay = 0
brokers = [{"ip":"zcoin.zapto.org", "port":9595, "192.111.130.31":9595}]#[{"ip":"zcoin.zapto.org", "port":6564}, {"ip":"192.111.130.31", "port":6565}]
version = "0.2.2"
host = "0.0.0.0"
port = 9595
nodes = landerdb.Connect("nodes.db")
wallet = landerdb.Connect("wallet.db")
db = landerdb.Connect("db.db")
コード例 #9
0
ファイル: quantum.py プロジェクト: f-prime/QuantumCoin
 def do_transactions(self, line):
     db = landerdb.Connect("transactions.db")
     print db.find("transactions", "all")
コード例 #10
0
ファイル: quantum.py プロジェクト: f-prime/QuantumCoin
                if get:
                    file.write(get)
                else:
                    break
        sock.close()
        print "Downloaded Nodes"


class Shell(cmd.Cmd):

    prompt = "QuantumShell$ "

    def do_transactions(self, line):
        db = landerdb.Connect("transactions.db")
        print db.find("transactions", "all")
    
    def do_send(self):
        pass

if __name__ == "__main__":
    if not os.path.exists("wallet.db"):
        db = landerdb.Connect("wallet.db")
        coins = landerdb.Connect("coins.db")
        transactions = landerdb.Connect("transactions.db")
        transactions.insert("transactions", {})
        db.insert("data", {uuid.uuid4().hex:uuid.uuid4().hex})
        coins.insert("coins", {})
    #threading.Thread(target=Shell().cmdloop).start()
    QuantumCoin().main()

コード例 #11
0
ファイル: db.py プロジェクト: f-prime/ByteMail
import landerdb

nodes = landerdb.Connect("nodes.db")
data = landerdb.Connect("data.db")
unsent = landerdb.Connect("unsent.db")
messages = landerdb.Connect("messages.db")
nonces = landerdb.Connect("nonces.db")
addressdb = landerdb.Connect("addressbook.db")
コード例 #12
0
 def __init__(self):
     self.sock = socket.socket()
     self.db = landerdb.Connect("nodes.db")
     self.port = 6554
     self.node_p = 5554
コード例 #13
0
#This is the file that will have all the config files such as where to find nodes and all the database connections
import landerdb

version = "0.1.1"
my_data = landerdb.Connect("data.db")
nodes = landerdb.Connect("nodes.db")
cache = landerdb.Connect(
    "cache.db"
)  # This is the local data such as messages that aren't held on the network itself.
master_dns = "sperre.ddns.org"
host = "0.0.0.0"
port = 7070
conversation_servers = {
}  # address:server Used by the nodes that are looking to send messages in an already open conversation
relay = False
found_convo = False
relaying_to = [
]  # For relay nodes only, this is a list of active connections that the node is proxying messages to.
コード例 #14
0
ファイル: db.py プロジェクト: avalleskey/Melody
import landerdb

db = landerdb.Connect("db.db")
コード例 #15
0
def checkin(data, obj, conn):
    print conn[0], "checked in"
    addr = data['addr']
    db = landerdb.Connect("nodes.db")
    db.insert("nodes", {conn[0]:5554, 'addr':addr})
    obj.close()