move utils to one utils.py file

This commit is contained in:
j 2014-05-18 00:18:32 +02:00
parent 084c8271c2
commit 53a9c296fb
6 changed files with 30 additions and 37 deletions

View File

@ -7,7 +7,7 @@ import logging
import json
from datetime import datetime
from ed25519_utils import valid
from utils import valid
import settings
from settings import db

View File

@ -1,18 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
import ed25519
ENCODING='base64'
def valid(key, value, sig):
'''
validate that value was signed by key
'''
vk = ed25519.VerifyingKey(str(key), encoding=ENCODING)
try:
vk.verify(str(sig), str(value), encoding=ENCODING)
#except ed25519.BadSignatureError:
except:
return False
return True

View File

@ -12,8 +12,7 @@ import thread
from threading import Thread
from settings import preferences, server, USER_ID, sk
from node.utils import get_public_ipv6
from ed25519_utils import valid
from utils import valid, get_public_ipv6
logger = logging.getLogger('oml.localnodes')

View File

@ -9,12 +9,11 @@ from tornado.httpserver import HTTPServer
import settings
import directory
import utils
import state
import user
import json
from ed25519_utils import valid
from utils import valid, get_public_ipv6
import api
import cert
@ -105,7 +104,7 @@ class ShareHandler(tornado.web.RequestHandler):
def publish_node():
host = utils.get_public_ipv6()
host = get_public_ipv6()
state.online = directory.put(settings.sk, {
'host': host,
'port': settings.server['node_port'],

View File

@ -1,13 +0,0 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
import socket
def get_public_ipv6():
host = ('2a01:4f8:120:3201::3', 25519)
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.connect(host)
ip = s.getsockname()[0]
s.close()
return ip

View File

@ -1,15 +1,21 @@
# -*- coding: utf-8 -*-
# vi:si:et:sw=4:sts=4:ts=4
from __future__ import division
import Image
from StringIO import StringIO
import re
import stdnum.isbn
import socket
import ox
import ed25519
from meta.utils import normalize_isbn, find_isbns
ENCODING='base64'
def valid_olid(id):
return id.startswith('OL') and id.endswith('M')
@ -82,3 +88,23 @@ def get_position_by_id(list, key):
return i
return -1
def valid(key, value, sig):
'''
validate that value was signed by key
'''
vk = ed25519.VerifyingKey(str(key), encoding=ENCODING)
try:
vk.verify(str(sig), str(value), encoding=ENCODING)
#except ed25519.BadSignatureError:
except:
return False
return True
def get_public_ipv6():
host = ('2a01:4f8:120:3201::3', 25519)
s = socket.socket(socket.AF_INET6, socket.SOCK_DGRAM)
s.connect(host)
ip = s.getsockname()[0]
s.close()
return ip