Exemple #1
0
    def __init__(self, nodenum, blockchain, artregistry):
        self.__logger = initlogging('', __name__)
        self.__blockchain = blockchain
        self.__artregistry = artregistry

        # nonces stores the nonces we have already seen
        self.__nonces = set()
Exemple #2
0
    def __init__(self, nodenum, nodeid, basedir, aliasmanager):
        # initialize logger
        # IMPORTANT: we must ALWAYS use self.__logger.* for logging and not logging.*,
        # since we need instance-level logging
        self.__logger = initlogging('', __name__)

        # our node id
        self.__nodeid = nodeid

        # the actual storage layer
        self.__storagedir = os.path.join(basedir, "chunkdata")
        self.__storage = ChunkStorage(self.__storagedir, mode=0o0700)

        # alias manager
        self.__alias_manager = aliasmanager

        # databases we keep
        self.__chunk_db = {}
        self.__missing_chunks = {}

        # tmp storage
        self.__tmpstoragedir = os.path.join(basedir, "tmpstorage")
        self.__tmpstorage = ChunkStorage(self.__tmpstoragedir, mode=0o0700)

        # run other initializations
        self.__initialize()
 def __init__(self, nodenum, privkey, pubkey, blockchain):
     self.__masternodes = {}
     self.__nodenum = nodenum
     self.__logger = initlogging('', __name__)
     self.__privkey = privkey
     self.__pubkey = pubkey
     self.__blockchain = blockchain
Exemple #4
0
    def __init__(self, nodenum, pubkey, artregistry, blockchain):
        self.__logger = initlogging('', __name__)
        self.__pubkey = pubkey
        self.__artregistry = artregistry
        self.__blockchain = blockchain

        self.__enabled = False
    def __init__(self, nodenum, file_data):
        self.__logger = initlogging('', __name__)

        if len(file_data) > NetWorkSettings.IMAGE_MAX_SIZE:
            raise ValueError("File is larger than NetWorkSettings.IMAGE_MAX_SIZE (%s)" % NetWorkSettings.IMAGE_MAX_SIZE)

        self.file_data = file_data
Exemple #6
0
 def __init__(self, nodenum):
     self.__logger = initlogging('', __name__)
     self.__artworks = {}
     self.__tickets = {}
     self.__owners = {}
     self.__matches = []
     self.__current_block_height = None
    def __init__(self, nodenum, nodeid, mn_manager):
        self.__logger = initlogging('', __name__)
        self.__nodeid = nodeid
        self.__mn_manager = mn_manager

        # helper lookup table for alias generation and other nodes
        aliases = []
        for i in range(NetWorkSettings.REPLICATION_FACTOR):
            digest_int = get_pynode_digest_int(
                i.to_bytes(1, byteorder='big') + NetWorkSettings.ALIAS_SEED)
            # self.__logger.debug("Alias digest %s -> %s" % (i, chunkid_to_hex(digest_int)))
            aliases.append(digest_int)

        self.__alias_digests = tuple(aliases)
    def __init__(self, privkey, pubkey, artregistry, chunkmanager,
                 aliasmanager):

        self.__logger = initlogging('Wallet interface', __name__)

        self.__privkey = privkey
        self.__pubkey = pubkey

        self.__artregistry = artregistry
        self.__chunkmanager = chunkmanager
        self.__blockchain = self.__connect_to_daemon()
        self.__chainwrapper = ChainWrapper(None, self.__blockchain,
                                           self.__artregistry)
        self.__aliasmanager = aliasmanager
        self.__nodemanager = ClientNodeManager(self.__privkey, self.__pubkey,
                                               self.__blockchain)

        self.__active_tasks = {}
    def __init__(self, nodenum, ip, port, privkey, pubkey):
        self.__logger = initlogging('', __name__)

        self.__nodenum = nodenum
        self.__ip = ip
        self.__port = port
        self.__privkey = privkey
        self.__pubkey = pubkey
        self.runner = None
        self.site = None

        # define our RPCs
        self.__RPCs = {}
        self.app = web.Application()
        self.app.add_routes([web.post('/', self.__http_proccess)])
        # self.app.on_shutdown.append(self.stop_server)

        self.__logger.debug("RPC listening on {}".format(self.__port))

        # add our only call
        self.add_callback("PING_REQ", "PING_RESP", self.__receive_rpc_ping)
Exemple #10
0
    def __init__(self):
        # initialize logging
        self.__logger = initlogging(int(0), __name__)
        self.__logger.debug("Started logger")
        self.basedir = os.getcwd()
        # load or generate keys
        daemon_keys = self.__load_or_create_keys(basedir=os.path.join(
            os.getcwd(), "keys"),
                                                 privname="private.key",
                                                 pubname="public.key")
        self.__privkey, self.__pubkey = daemon_keys

        # set up BlockChain object
        self.blockchain = self.__connect_to_daemon()

        # spawn logic
        self.logic = MasterNodeLogic(nodenum=0,
                                     blockchain=self.blockchain,
                                     basedir=self.basedir,
                                     privkey=self.__privkey,
                                     pubkey=self.__pubkey)
Exemple #11
0
    def __init__(self, privkey, pubkey, nodeid, server_ip, server_port, mnpubkey):
        if type(nodeid) is not int:
            raise TypeError("nodeid must be int!")

        self.__logger = initlogging('', __name__, level="debug")

        # variables of the client
        self.__privkey = privkey
        self.__pubkey = pubkey

        # variables of the server (the MN)
        self.__server_nodeid = nodeid
        self.__server_ip = server_ip
        self.server_ip = server_ip
        self.__server_port = server_port
        self.__server_pubkey = mnpubkey

        # pubkey and nodeid should be public for convenience, so that we can identify which server this is
        self.pubkey = self.__server_pubkey
        self.nodeid = nodeid
        self.__name = MASTERNODE_NAMES.get(server_ip)
        # TODO
        self.__reputation = None
Exemple #12
0
import uuid
import asyncio
from datetime import datetime

from aiohttp import ClientConnectorError

from core_modules.ticket_models import RegistrationTicket, Signature, FinalRegistrationTicket, ActivationTicket, \
    FinalActivationTicket, ImageData
from PastelCommon.signatures import pastel_id_write_signature_on_data_func
from core_modules.settings import NetWorkSettings
from core_modules.helpers import require_true
from core_modules.logger import initlogging
from debug.masternode_conf import MASTERNODE_NAMES
from wallet.database import RegticketDB

art_reg_client_logger = initlogging('Logger', __name__)


class ArtRegistrationClient:
    def __init__(self, privkey, pubkey, chainwrapper, nodemanager):
        self.__chainwrapper = chainwrapper
        self.__nodemanager = nodemanager

        # get MN ordering
        self.__privkey = privkey
        self.__pubkey = pubkey

    def __generate_signed_ticket(self, ticket):
        signed_ticket = Signature(dictionary={
            "signature": pastel_id_write_signature_on_data_func(ticket.serialize(), self.__privkey, self.__pubkey),
            "pubkey": self.__pubkey,
Exemple #13
0
 def __init__(self, nodenum, chunkmanager, mn_manager, aliasmanager):
     self.__logger = initlogging('', __name__)
     self.__chunkmanager = chunkmanager
     self.__aliasmanager = aliasmanager
     self.__mn_manager = mn_manager
from core_modules.helpers import get_pynode_digest_bytes, require_true
from PastelCommon.signatures import pastel_id_verify_signature_with_public_key_func
from core_modules.logger import initlogging
from core_modules.model_validators import FieldValidator, StringField, IntegerField, FingerprintField, SHA3512Field, \
    LubyChunkHashField, LubyChunkField, ImageField, ThumbnailField, TXIDField, UUIDField, SignatureField, PubkeyField, \
    LubySeedField, BlockChainAddressField, UnixTimeField, StringChoiceField
from PastelCommon.dupe_detection import DupeDetector
from core_modules.blackbox_modules.dupe_detection_utils import measure_similarity, assemble_fingerprints_for_pandas
from core_modules.settings import NetWorkSettings

from core_modules.blackbox_modules.nsfw import NSFWDetector

from core_modules.blackbox_modules import luby

ticket_logger = initlogging('Ticket logger', __name__)


# ===== VALIDATORS ===== #
class NotImplementedValidator:
    msg = "You forgot to set \"validators\" while inheriting from ModelBase!"

    def __index__(self):
        raise NotImplementedError(self.msg)

    def __getattr__(self, item):
        raise NotImplementedError(self.msg)

    def __call__(self, *args, **kwargs):
        raise NotImplementedError(self.msg)
Exemple #15
0
 def __init__(self, privkey, pubkey, blockchain):
     self.__logger = initlogging('ClientNodeManager', __name__)
     self.__privkey = privkey
     self.__pubkey = pubkey
     self.__blockchain = blockchain
Exemple #16
0
from peewee import DoesNotExist

from core_modules.blackbox_modules.nsfw import NSFWDetector
from core_modules.database import Regticket, db, REGTICKET_STATUS_ERROR
from debug.masternode_conf import MASTERNODE_NAMES
from pynode.utils import get_masternode_ordering
from .ticket_models import RegistrationTicket, Signature, FinalRegistrationTicket, ActivationTicket, \
    FinalActivationTicket, ImageData, IDTicket, FinalIDTicket, TransferTicket, FinalTransferTicket, TradeTicket, \
    FinalTradeTicket
from PastelCommon.signatures import pastel_id_write_signature_on_data_func
from core_modules.helpers import require_true, bytes_to_chunkid
from core_modules.jailed_image_parser import JailedImageParser
from core_modules.logger import initlogging

mn_ticket_logger = initlogging('Logger', __name__)


def generate_final_regticket(ticket, signature, mn_signatures):
    # create combined registration ticket
    final_ticket = FinalRegistrationTicket(
        dictionary={
            "ticket": ticket.to_dict(),
            "signature_author": signature.to_dict(),
            "signature_1": mn_signatures[0].to_dict(),
            "signature_2": mn_signatures[1].to_dict(),
            "signature_3": mn_signatures[2].to_dict(),
            "nonce": str(uuid.uuid4()),
        })
    return final_ticket
 def __init__(self, user, password, ip, rpcport):
     self.url = "http://%s:%s@%s:%s" % (user, password, ip, rpcport)
     self.__reconnect()
     self.__logger = initlogging('', __name__)
    def __init__(self, nodenum, blockchain, basedir, privkey, pubkey):
        self.__name = "node%s" % nodenum
        self.__nodenum = nodenum
        self.__nodeid = get_nodeid_from_pubkey(pubkey)
        self.__basedir = basedir
        self.__privkey = privkey
        self.__pubkey = pubkey
        self.__ip = '0.0.0.0'
        self.__port = 4444

        self.__logger = initlogging('', __name__)
        self.__blockchain = blockchain

        # the art registry
        self.__artregistry = ArtRegistry(self.__nodenum)

        # set up ChainWrapper
        self.__chainwrapper = ChainWrapper(self.__nodenum, self.__blockchain,
                                           self.__artregistry)

        # the automatic trader
        self.__autotrader = AutoTrader(self.__nodenum, self.__pubkey,
                                       self.__artregistry, self.__blockchain)

        # masternode manager
        self.__mn_manager = NodeManager(self.__nodenum, self.__privkey,
                                        self.__pubkey, blockchain)

        # alias manager
        self.__aliasmanager = AliasManager(self.__nodenum, self.__nodeid,
                                           self.__mn_manager)

        # chunk manager
        self.__chunkmanager = ChunkManager(self.__nodenum, self.__nodeid,
                                           basedir, self.__aliasmanager)

        # refresh masternode list
        self.__refresh_masternode_list()

        self.__chunkmanager_rpc = ChunkManagerRPC(self.__nodenum,
                                                  self.__chunkmanager,
                                                  self.__mn_manager,
                                                  self.__aliasmanager)

        # art registration server
        self.__artregistrationserver = ArtRegistrationServer(
            self.__nodenum, self.__privkey, self.__pubkey, self.__chainwrapper,
            self.__chunkmanager, self.__blockchain)

        # django interface
        # replace RPC interface to http

        # functions exposed from chunkmanager
        # self.load_full_chunks = self.__chunkmanager.load_full_chunks

        # start rpc server
        self.__rpcserver = RPCServer(self.__nodenum, self.__ip, self.__port,
                                     self.__privkey, self.__pubkey)

        # TODO: the are blocking calls. We should turn them into coroutines if possible!
        # TODO: we should ACL who can access these RPCs, chunk related RPC is only for MNs!
        self.__rpcserver.add_callback(
            "SPOTCHECK_REQ", "SPOTCHECK_RESP",
            self.__chunkmanager_rpc.receive_rpc_spotcheck)
        self.__rpcserver.add_callback(
            "FETCHCHUNK_REQ", "FETCHCHUNK_RESP",
            self.__chunkmanager_rpc.receive_rpc_fetchchunk)

        self.__artregistrationserver.register_rpcs(self.__rpcserver)

        # we like to enable/disable this from masternodedaemon
        self.issue_random_tests_forever = self.__chunkmanager_rpc.issue_random_tests_forever