check for oserror when binding local ips
This commit is contained in:
parent
8c72242eaf
commit
75c8abd9e0
@ -20,7 +20,7 @@
|
||||
import flask, cgi
|
||||
from flask import request, Response, abort, send_from_directory
|
||||
from gevent.pywsgi import WSGIServer
|
||||
import sys, random, threading, hmac, hashlib, base64, time, math, os, json
|
||||
import sys, random, threading, hmac, hashlib, base64, time, math, os, json, socket
|
||||
import core
|
||||
from onionrblockapi import Block
|
||||
import onionrutils, onionrexceptions, onionrcrypto, blockimporter, onionrevents as events, logger, config, onionr
|
||||
@ -47,9 +47,19 @@ def setBindIP(filePath):
|
||||
'''Set a random localhost IP to a specified file (intended for private or public API localhost IPs)'''
|
||||
hostOctets = [str(127), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF)), str(random.randint(0x02, 0xFF))]
|
||||
data = '.'.join(hostOctets)
|
||||
|
||||
|
||||
# Try to bind IP. Some platforms like Mac block non normal 127.x.x.x
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.bind((data, 0))
|
||||
except OSError:
|
||||
logger.warn('Your platform appears to not support random local host addresses 127.x.x.x. Falling back to 127.0.0.1.')
|
||||
data = '127.0.0.1'
|
||||
s.close()
|
||||
|
||||
with open(filePath, 'w') as bindFile:
|
||||
bindFile.write(data)
|
||||
|
||||
return data
|
||||
|
||||
class PublicAPI:
|
||||
|
@ -737,7 +737,7 @@ class Block:
|
||||
return (blocks[-1], blocks)
|
||||
return blocks[-1]
|
||||
|
||||
def exists(hash):
|
||||
def exists(bHash):
|
||||
'''
|
||||
Checks if a block is saved to file or not
|
||||
|
||||
@ -751,7 +751,7 @@ class Block:
|
||||
'''
|
||||
|
||||
# no input data? scrap it.
|
||||
if hash is None:
|
||||
if bHash is None:
|
||||
return False
|
||||
'''
|
||||
if type(hash) == Block:
|
||||
@ -759,8 +759,10 @@ class Block:
|
||||
else:
|
||||
blockfile = onionrcore.Core().dataDir + 'blocks/%s.dat' % hash
|
||||
'''
|
||||
|
||||
ret = isinstance(onionrstorage.getData(onionrcore.Core(), hash.getHash()), type(None))
|
||||
if isinstance(bHash, Block):
|
||||
bHash = bHash.getHash()
|
||||
|
||||
ret = isinstance(onionrstorage.getData(onionrcore.Core(), bHash), type(None))
|
||||
|
||||
return not ret
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user