import re
from cryptography.hazmat.primitives.asymmetric import ec

class Globals:
	NDOES= [0,1,2,3,4,5,6,7,8,9]

	NEW_ITEM_PATH= '/submit'
	RPC_PATH= '/network'

	SESSION_VALIDITY= 8*60*60
	MAXIMUM_IDENTIFICATION_DELAY = 5
	BLOCK_CREATION_TAKEOVER= 3
	MAXIMUM_RETRIES=3
	BLOCK_CREATION_INTERVAL = 30
	BLOCK_CREATION_TAKEOVER = 10
	BLOCK_DUTY_DELAY = 10
	GENESIS_BLOCK= '0000000000000000000000000000000000000000000000000000000000000000'
	MIN_BLOCK_SIZE= 425
	BLOCK_EXTENSION= '.blk'
	
	RESOURCES_RESOURCE_CODE = 'RESOURCES'
	NETWORK_RESOURCE_CODE = 'NETWORK'
	NODE_NETWORK_ROLE = 'worker'
	NODE_ID_PREFIX = 'BLOCKMESHWORKERNODE'
	CONTROLLER_ID_PREFIX = 'BLOCKMESHCONTROLLER'

	DATABASE_BLOCK_PREFIX = 'block'
	DATABASE_KEY_PREFIX = 'key'
	DATABASE_SESSION_PREFIX = 'session'
	DATABASE_KEY_SEPARATOR = '.'

	JSON_MEMORY_MULTIPLIER = 10

class Patterns:
	WORKER= r'^[0-9]$'
	HASH= r'^[a-f0-9]{64}$'
	SIGNATURE= r'^([A-F0-9]{100,}|[a-zA-Z0-9+=/]{50,})$'
	TIMESTAMP= r'^\d{10,20}$'

	@staticmethod
	def validate(pattern, data):
		return (re.match(pattern, data) != None)
