Skip to content

Commit

Permalink
VENOM-302: Add more tox connection options
Browse files Browse the repository at this point in the history
  • Loading branch information
naxuroqa committed Apr 8, 2018
1 parent ced9296 commit 5a52934
Show file tree
Hide file tree
Showing 5 changed files with 421 additions and 23 deletions.
4 changes: 4 additions & 0 deletions src/db/DatabaseInterfaces.vala
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ namespace Venom {
public abstract bool enable_custom_proxy { get; set; }
public abstract string custom_proxy_host { get; set; }
public abstract int custom_proxy_port { get; set; }
public abstract bool enable_udp { get; set; }
public abstract bool enable_ipv6 { get; set; }
public abstract bool enable_local_discovery { get; set; }
public abstract bool enable_hole_punching { get; set; }

public abstract void load();
public abstract void save();
Expand Down
64 changes: 47 additions & 17 deletions src/db/SqliteSettingsDatabase.vala
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ namespace Venom {
public bool enable_custom_proxy { get; set; default = false; }
public string custom_proxy_host { get; set; default = "localhost"; }
public int custom_proxy_port { get; set; default = 9150; }
public bool enable_udp { get; set; default = true; }
public bool enable_ipv6 { get; set; default = true; }
public bool enable_local_discovery { get; set; default = true; }
public bool enable_hole_punching { get; set; default = true; }

private const string CREATE_TABLE_SETTINGS = """
CREATE TABLE IF NOT EXISTS Settings (
Expand All @@ -50,7 +54,11 @@ namespace Venom {
enableproxy INTEGER NOT NULL,
enablecustomproxy INTEGER NOT NULL,
customproxyhost STRING NOT NULL,
customproxyport INTEGER NOT NULL
customproxyport INTEGER NOT NULL,
enableudp INTEGER NOT NULL,
enableipv6 INTEGER NOT NULL,
enablelocaldiscovery INTEGER NOT NULL,
enableholepunching INTEGER NOT NULL
);
""";

Expand All @@ -68,7 +76,11 @@ namespace Venom {
ENABLE_PROXY,
ENABLE_CUSTOM_PROXY,
CUSTOM_PROXY_HOST,
CUSTOM_PROXY_PORT
CUSTOM_PROXY_PORT,
ENABLE_UDP,
ENABLE_IPV6,
ENABLE_LOCAL_DISCOVERY,
ENABLE_HOLE_PUNCHING
}

private const string TABLE_ID = "$ID";
Expand All @@ -85,23 +97,33 @@ namespace Venom {
private const string TABLE_ENABLE_CUSTOM_PROXY = "$CUSTOMPROXY";
private const string TABLE_CUSTOM_PROXY_HOST = "$CUSTOMPROXYHOST";
private const string TABLE_CUSTOM_PROXY_PORT = "$CUSTOMPROXYPORT";
private const string TABLE_UDP = "$UDP";
private const string TABLE_IPV6 = "$IPV6";
private const string TABLE_LOCAL_DISCOVERY = "$LOCALDISCOVERY";
private const string TABLE_HOLE_PUNCHING = "$HOLEPUNCHING";

private static string STATEMENT_INSERT_SETTINGS =
"INSERT OR REPLACE INTO Settings (id, darktheme, animations, logging, urgencynotification, tray, notify, infinitelog, sendtyping, daystolog, enableproxy, enablecustomproxy, customproxyhost, customproxyport)"
+ " VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);".printf(TABLE_ID,
TABLE_DARKTHEME,
TABLE_ANIMATIONS,
TABLE_LOGGING,
TABLE_URGENCYNOTIFICATIONS,
TABLE_TRAY,
TABLE_NOTIFY,
TABLE_INFINITELOG,
TABLE_SENDTYPING,
TABLE_DAYSTOLOG,
TABLE_ENABLE_PROXY,
TABLE_ENABLE_CUSTOM_PROXY,
TABLE_CUSTOM_PROXY_HOST,
TABLE_CUSTOM_PROXY_PORT);
"INSERT OR REPLACE INTO Settings (id, darktheme, animations, logging, urgencynotification, tray, notify, infinitelog, sendtyping, daystolog, enableproxy, enablecustomproxy, customproxyhost, customproxyport, enableudp, enableipv6, enablelocaldiscovery, enableholepunching)"
+ " VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s);"
.printf(TABLE_ID,
TABLE_DARKTHEME,
TABLE_ANIMATIONS,
TABLE_LOGGING,
TABLE_URGENCYNOTIFICATIONS,
TABLE_TRAY,
TABLE_NOTIFY,
TABLE_INFINITELOG,
TABLE_SENDTYPING,
TABLE_DAYSTOLOG,
TABLE_ENABLE_PROXY,
TABLE_ENABLE_CUSTOM_PROXY,
TABLE_CUSTOM_PROXY_HOST,
TABLE_CUSTOM_PROXY_PORT,
TABLE_UDP,
TABLE_IPV6,
TABLE_LOCAL_DISCOVERY,
TABLE_HOLE_PUNCHING);

private static string STATEMENT_SELECT_SETTINGS = "SELECT * FROM Settings WHERE id = 0";

private IDatabaseStatement insertStatement;
Expand Down Expand Up @@ -150,6 +172,10 @@ namespace Venom {
enable_custom_proxy = selectStatement.column_bool(SettingsColumn.ENABLE_CUSTOM_PROXY);
custom_proxy_host = selectStatement.column_text(SettingsColumn.CUSTOM_PROXY_HOST);
custom_proxy_port = selectStatement.column_int(SettingsColumn.CUSTOM_PROXY_PORT);
enable_udp = selectStatement.column_bool(SettingsColumn.ENABLE_UDP);
enable_ipv6 = selectStatement.column_bool(SettingsColumn.ENABLE_IPV6);
enable_local_discovery = selectStatement.column_bool(SettingsColumn.ENABLE_LOCAL_DISCOVERY);
enable_hole_punching = selectStatement.column_bool(SettingsColumn.ENABLE_HOLE_PUNCHING);
} else {
logger.i("No settings entry found.");
}
Expand Down Expand Up @@ -177,6 +203,10 @@ namespace Venom {
.bind_bool(TABLE_ENABLE_CUSTOM_PROXY, enable_custom_proxy)
.bind_text(TABLE_CUSTOM_PROXY_HOST, custom_proxy_host)
.bind_int(TABLE_CUSTOM_PROXY_PORT, custom_proxy_port)
.bind_bool(TABLE_UDP, enable_udp)
.bind_bool(TABLE_IPV6, enable_ipv6)
.bind_bool(TABLE_LOCAL_DISCOVERY, enable_local_discovery)
.bind_bool(TABLE_HOLE_PUNCHING, enable_hole_punching)
.step();
} catch (DatabaseStatementError e) {
logger.e("Could not insert settings into database: " + e.message);
Expand Down
9 changes: 6 additions & 3 deletions src/tox/ToxSession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ namespace Venom {
var options_error = ToxCore.ErrOptionsNew.OK;
var options = new ToxCore.Options(ref options_error);

//options.log_callback = on_tox_message;
options.log_callback = on_tox_message;
friends = new GLib.HashTable<uint32, IContact>(null, null);

var savedata = iohandler.load_sessiondata();
Expand All @@ -151,6 +151,11 @@ namespace Venom {
init_proxy(options);
}

options.udp_enabled = settings_database.enable_udp;
options.ipv6_enabled = settings_database.enable_ipv6;
options.local_discovery_enabled = settings_database.enable_local_discovery;
options.hole_punching_enabled = settings_database.enable_hole_punching;

// create handle
var error = ToxCore.ErrNew.OK;
handle = new ToxCore.Tox(options, ref error);
Expand Down Expand Up @@ -198,7 +203,6 @@ namespace Venom {

private void init_proxy(ToxCore.Options options) {
if (settings_database.enable_custom_proxy) {
options.udp_enabled = false;
options.proxy_type = ProxyType.SOCKS5;
options.proxy_host = settings_database.custom_proxy_host;
options.proxy_port = (uint16) settings_database.custom_proxy_port;
Expand Down Expand Up @@ -226,7 +230,6 @@ namespace Venom {
if (proxy.has_prefix("socks5:")) {
GLib.MatchInfo info = null;
if (proxy_regex != null && proxy_regex.match(proxy, 0, out info)) {
options.udp_enabled = false;
options.proxy_type = ProxyType.SOCKS5;
options.proxy_host = info.fetch_named("host");
options.proxy_port = (uint16) int.parse(info.fetch_named("port"));
Expand Down

0 comments on commit 5a52934

Please sign in to comment.