Implement client-side bindhost
This commit is contained in:
parent
59243f492f
commit
6af738107b
3 changed files with 14 additions and 11 deletions
|
@ -5,22 +5,23 @@ class Table(object):
|
|||
self.database = database
|
||||
|
||||
class Servers(Table):
|
||||
def add(self, alias, hostname, port, password, ipv4, tls, nickname,
|
||||
username=None, realname=None):
|
||||
def add(self, alias, hostname, port, password, ipv4, tls, bindhost,
|
||||
nickname, username=None, realname=None):
|
||||
username = username or nickname
|
||||
realname = realname or nickname
|
||||
self.database.execute(
|
||||
"""INSERT INTO servers (alias, hostname, port, password, ipv4,
|
||||
tls, nickname, username, realname) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
[hostname, port, password, ipv4, tls, nickname, username, realname])
|
||||
tls, bindhost, nickname, username, realname) VALUES (
|
||||
?, ?, ?, ?, ?, ?, ?, ?, ?)""",
|
||||
[hostname, port, password, ipv4, tls, bindhost, nickname, username,
|
||||
realname])
|
||||
def get_all(self):
|
||||
return self.database.execute_fetchall(
|
||||
"SELECT server_id, alias FROM servers")
|
||||
def get(self, id):
|
||||
return self.database.execute_fetchone(
|
||||
"""SELECT server_id, alias, hostname, port, password, ipv4,
|
||||
tls, nickname, username, realname FROM servers WHERE
|
||||
tls, bindhost, nickname, username, realname FROM servers WHERE
|
||||
server_id=?""",
|
||||
[id])
|
||||
|
||||
|
@ -304,8 +305,8 @@ class Database(object):
|
|||
if not self.has_table("servers"):
|
||||
self.execute("""CREATE TABLE servers
|
||||
(server_id INTEGER PRIMARY KEY, alias TEXT, hostname TEXT,
|
||||
port INTEGER,password TEXT,ipv4 BOOLEAN, tls BOOLEAN,
|
||||
nickname TEXT, username TEXT, realname TEXT)""")
|
||||
port INTEGER, password TEXT, ipv4 BOOLEAN, tls BOOLEAN,
|
||||
bindhost TEXT, nickname TEXT, username TEXT, realname TEXT)""")
|
||||
def make_channels_table(self):
|
||||
if not self.has_table("channels"):
|
||||
self.execute("""CREATE TABLE channels
|
||||
|
|
|
@ -23,11 +23,11 @@ class Bot(object):
|
|||
self.poll = select.epoll()
|
||||
|
||||
def add_server(self, server_id, connect=True):
|
||||
(_, alias, hostname, port, password, ipv4, tls, nickname,
|
||||
(_, alias, hostname, port, password, ipv4, tls, bindhost, nickname,
|
||||
username, realname) = self.database.servers.get(server_id)
|
||||
|
||||
new_server = IRCServer.Server(self, self._events, server_id, alias,
|
||||
hostname, port, password, ipv4, tls, nickname, username,
|
||||
hostname, port, password, ipv4, tls, bindhost, nickname, username,
|
||||
realname)
|
||||
if not new_server.get_setting("connect", True):
|
||||
return
|
||||
|
|
|
@ -8,7 +8,7 @@ PING_INTERVAL_SECONDS = 30
|
|||
|
||||
class Server(IRCObject.Object):
|
||||
def __init__(self, bot, events, id, alias, hostname, port, password,
|
||||
ipv4, tls, nickname, username, realname):
|
||||
ipv4, tls, bindhost, nickname, username, realname):
|
||||
self.connected = False
|
||||
self.bot = bot
|
||||
self.events = events
|
||||
|
@ -59,6 +59,8 @@ class Server(IRCObject.Object):
|
|||
self.socket = socket.socket(socket.AF_INET6,
|
||||
socket.SOCK_STREAM)
|
||||
|
||||
if bindhost:
|
||||
self.socket.bind((bindhost, 0))
|
||||
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
|
||||
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
|
||||
self.socket.settimeout(5.0)
|
||||
|
|
Loading…
Reference in a new issue