Skip to content

Commit

Permalink
fixed some windows bugs (ipv6 won't work for me, will look into it la…
Browse files Browse the repository at this point in the history
…ter)
  • Loading branch information
naxuroqa committed Oct 1, 2013
1 parent 5916062 commit 3cb3ea4
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/core/DhtServer.vala
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ namespace Venom {
public uint16 port {get; set;}
public uint8[] pub_key {get; set;}
public bool ipv6 {get; set;}
public DhtServer() {
}
public DhtServer.withArgs(string ip, uint16 port, uint8[] pub_key, bool ipv6 = true) {

public DhtServer.with_args(string ip, uint16 port, uint8[] pub_key, bool ipv6 = false) {
assert(pub_key.length == 32);
this.ip = ip;
this.port = port;
this.pub_key = Tools.clone(pub_key, pub_key.length);
this.ipv6 = ipv6;
}
public string toString() {
public string to_string() {
return "%s:%u%s %s".printf(ip, uint16.from_big_endian(port), ipv6 ? " (ipv6)" : "", Tools.bin_to_hexstring(pub_key));
}
}
Expand Down
13 changes: 8 additions & 5 deletions src/core/ToxSession.vala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ namespace Venom {
private unowned Thread<int> session_thread = null;
#endif
private bool bootstrapped = false;
private bool ipv6 = false;
public bool running {get; private set; default=false; }
public bool connected { get; private set; default=false; }
public DhtServer connected_dht_server { get; private set; default=null; }
Expand All @@ -40,15 +41,17 @@ namespace Venom {
public signal void on_connectionstatus(int friend_number, bool status);
public signal void on_ownconnectionstatus(bool status);

public ToxSession() {
public ToxSession( bool ipv6 = false ) {
this.ipv6 = ipv6;

// create handle
handle = new Tox.Tox(1);
handle = new Tox.Tox( ipv6 ? 1 : 0);

// Add one default dht server
string ip = "192.184.81.118";
uint16 port = ((uint16)33445).to_big_endian();
uint8[] pub_key = Tools.hexstring_to_bin("5CD7EB176C19A2FD840406CD56177BB8E75587BB366F7BB3004B19E3EDC04143");
dht_servers.add(new DhtServer.withArgs(ip, port, pub_key));
dht_servers.add(new DhtServer.with_args(ip, port, pub_key));

// setup callbacks
handle.callback_friendrequest(this.on_friendrequest_callback);
Expand Down Expand Up @@ -279,7 +282,7 @@ namespace Venom {
stdout.printf("Background thread started.\n");
lock(handle) {
if(!bootstrapped) {
stdout.printf("Connecting to DHT server:\n%s\n", dht_servers[0].toString());
stdout.printf("Connecting to DHT server:\n%s\n", dht_servers[0].to_string());
handle.bootstrap_from_address(dht_servers[0].ip, dht_servers[0].ipv6 ? 1 : 0, dht_servers[0].port, dht_servers[0].pub_key);
bootstrapped = true;
}
Expand All @@ -291,8 +294,8 @@ namespace Venom {
new_status = (handle.isconnected() != 0);
}
if(new_status && !connected) {
Idle.add(() => { on_ownconnectionstatus(true); return false; });
connected_dht_server = dht_servers[0];
Idle.add(() => { on_ownconnectionstatus(true); return false; });
} else if(!new_status && connected) {
Idle.add(() => { on_ownconnectionstatus(false); return false; });
}
Expand Down
4 changes: 2 additions & 2 deletions src/ui/ContactListWindow.vala
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,10 @@ namespace Venom {
private void on_ownconnectionstatus(bool status) {
if(status) {
image_status.set_from_pixbuf(ResourceFactory.instance.online);
image_status.set_tooltip_text("Connected to: %s".printf(session.connected_dht_server.toString()));
image_status.set_tooltip_text("Connected to: %s".printf(session.connected_dht_server.to_string()));
} else {
image_status.set_from_pixbuf(ResourceFactory.instance.offline);
image_status.set_tooltip_text("");
image_status.set_tooltip_text("Not connected.");
}
}

Expand Down
2 changes: 1 addition & 1 deletion testing/GroupTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace Testing {
private int groupchat_number = 0;
private Gee.List<int> new_contacts = new Gee.ArrayList<int>();
private Gee.List<int> online_contacts = new Gee.ArrayList<int>();
public GroupTest( bool ipv6 = true ) {
public GroupTest( bool ipv6 = false ) {
tox = new Tox.Tox(ipv6 ? 1 : 0);
tox.callback_friendrequest(on_friend_request);
tox.callback_group_message(on_groupchat_message);
Expand Down
6 changes: 3 additions & 3 deletions testing/ToxVapiTest.vala
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,19 @@

namespace Testing {
public class ToxTest {
public void run_connection_test(string ip_string, string pub_key_string, int port = 33445, int timeout = 5000, bool ipv6 = true) {
public void run_connection_test(string ip_string, string pub_key_string, int port = 33445, int timeout = 100, bool ipv6 = false) {
Tox.Tox tox = new Tox.Tox(ipv6 ? 1 : 0);
string ip_address = ip_string;
uint16 ip_port_be = ((uint16)port).to_big_endian();
uint8[] pub_key = Venom.Tools.hexstring_to_bin(pub_key_string);

stdout.printf("Connecting to: %s:%u\n", ip_address, uint16.from_big_endian(ip_port_be));
stdout.printf("Connecting to: %s:%u\n", ip_address, port);
stdout.printf("Public key: %s\n", pub_key_string);

tox.bootstrap_from_address(ip_address, ipv6 ? 1 : 0, ip_port_be, pub_key);

bool connected = false;
for(int i = 0; i < 1000; ++i) {
for(int i = 0; i < timeout; ++i) {
if(connected = (tox.isconnected() != 0))
break;
tox.do();
Expand Down

0 comments on commit 3cb3ea4

Please sign in to comment.