mac invites: don't check certificate
This commit is contained in:
parent
211394649f
commit
7fb8cc587f
|
@ -56,140 +56,138 @@ namespace SparkleLib {
|
||||||
{
|
{
|
||||||
this.is_connecting = true;
|
this.is_connecting = true;
|
||||||
|
|
||||||
this.thread = new Thread (
|
this.thread = new Thread (() => {
|
||||||
new ThreadStart (delegate {
|
int port = Server.Port;
|
||||||
int port = Server.Port;
|
|
||||||
|
|
||||||
if (port < 0)
|
if (port < 0)
|
||||||
port = 80;
|
port = 80;
|
||||||
|
|
||||||
|
try {
|
||||||
|
this.socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) {
|
||||||
|
ReceiveTimeout = 5 * 1000,
|
||||||
|
SendTimeout = 5 * 1000
|
||||||
|
};
|
||||||
|
|
||||||
|
// Try to connect to the server
|
||||||
|
this.socket.Connect (Server.Host, port);
|
||||||
|
|
||||||
|
this.is_connecting = false;
|
||||||
|
this.is_connected = true;
|
||||||
|
|
||||||
|
OnConnected ();
|
||||||
|
|
||||||
|
// Subscribe to channels of interest to us
|
||||||
|
foreach (string channel in base.channels)
|
||||||
|
AlsoListenToInternal (channel);
|
||||||
|
|
||||||
|
} catch (SocketException e) {
|
||||||
|
this.is_connected = false;
|
||||||
|
this.is_connecting = false;
|
||||||
|
|
||||||
|
if (this.socket != null)
|
||||||
|
this.socket.Close ();
|
||||||
|
|
||||||
|
OnDisconnected (e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
byte [] bytes = new byte [4096];
|
||||||
|
int bytes_read = 0;
|
||||||
|
this.last_ping = DateTime.Now;
|
||||||
|
|
||||||
|
// Wait for messages
|
||||||
|
while (this.is_connected) {
|
||||||
try {
|
try {
|
||||||
this.socket = new Socket (AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp) {
|
// This blocks the thread
|
||||||
ReceiveTimeout = 5 * 1000,
|
int i = 0;
|
||||||
SendTimeout = 5 * 1000
|
int timeout = 300;
|
||||||
};
|
while (this.socket.Available < 1) {
|
||||||
|
try {
|
||||||
|
// We've timed out, let's ping the server to
|
||||||
|
// see if the connection is still up
|
||||||
|
if (i == timeout) {
|
||||||
|
SparkleHelpers.DebugInfo ("ListenerTcp",
|
||||||
|
"Pinging " + Server);
|
||||||
|
|
||||||
// Try to connect to the server
|
byte [] ping_bytes = Encoding.UTF8.GetBytes ("ping\n");
|
||||||
this.socket.Connect (Server.Host, port);
|
byte [] pong_bytes = new byte [4096];
|
||||||
|
|
||||||
this.is_connecting = false;
|
this.socket.Send (ping_bytes);
|
||||||
this.is_connected = true;
|
|
||||||
|
|
||||||
OnConnected ();
|
if (this.socket.Receive (pong_bytes) < 1)
|
||||||
|
// 10057 means "Socket is not connected"
|
||||||
|
throw new SocketException (10057);
|
||||||
|
|
||||||
// Subscribe to channels of interest to us
|
SparkleHelpers.DebugInfo ("ListenerTcp", "Received pong from " + Server);
|
||||||
foreach (string channel in base.channels)
|
|
||||||
AlsoListenToInternal (channel);
|
|
||||||
|
|
||||||
} catch (SocketException e) {
|
i = 0;
|
||||||
this.is_connected = false;
|
this.last_ping = DateTime.Now;
|
||||||
this.is_connecting = false;
|
|
||||||
|
|
||||||
if (this.socket != null)
|
} else {
|
||||||
this.socket.Close ();
|
|
||||||
|
|
||||||
OnDisconnected (e.Message);
|
// Check when the last ping occured. If it's
|
||||||
|
// significantly longer than our regular interval the
|
||||||
|
// system likely woke up from sleep and we want to
|
||||||
|
// simulate a disconnect
|
||||||
|
int sleepiness = DateTime.Compare (
|
||||||
|
this.last_ping.AddMilliseconds (timeout * 1000 * 1.2),
|
||||||
|
DateTime.Now
|
||||||
|
);
|
||||||
|
|
||||||
|
if (sleepiness <= 0) {
|
||||||
|
SparkleHelpers.DebugInfo ("ListenerTcp", "System woke up from sleep");
|
||||||
|
|
||||||
|
// 10057 means "Socket is not connected"
|
||||||
|
throw new SocketException (10057);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// The ping failed: disconnect completely
|
||||||
|
} catch (SocketException e) {
|
||||||
|
this.is_connected = false;
|
||||||
|
this.is_connecting = false;
|
||||||
|
|
||||||
|
if (this.socket != null) {
|
||||||
|
this.socket.Close ();
|
||||||
|
this.socket = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
OnDisconnected ("Ping timeout: " + e.Message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread.Sleep (1000);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (Exception) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (this.socket.Available > 0)
|
||||||
|
bytes_read = this.socket.Receive (bytes);
|
||||||
|
|
||||||
byte [] bytes = new byte [4096];
|
// Parse the received message
|
||||||
int bytes_read = 0;
|
if (bytes_read > 0) {
|
||||||
this.last_ping = DateTime.Now;
|
string received = Encoding.UTF8.GetString (bytes);
|
||||||
|
string line = received.Substring (0, received.IndexOf ("\n"));
|
||||||
|
|
||||||
// Wait for messages
|
if (!line.Contains ("!"))
|
||||||
while (this.is_connected) {
|
continue;
|
||||||
try {
|
|
||||||
// This blocks the thread
|
|
||||||
int i = 0;
|
|
||||||
int timeout = 300;
|
|
||||||
while (this.socket.Available < 1) {
|
|
||||||
try {
|
|
||||||
// We've timed out, let's ping the server to
|
|
||||||
// see if the connection is still up
|
|
||||||
if (i == timeout) {
|
|
||||||
SparkleHelpers.DebugInfo ("ListenerTcp",
|
|
||||||
"Pinging " + Server);
|
|
||||||
|
|
||||||
byte [] ping_bytes = Encoding.UTF8.GetBytes ("ping\n");
|
string folder_identifier = line.Substring (0, line.IndexOf ("!"));
|
||||||
byte [] pong_bytes = new byte [4096];
|
string message = CleanMessage (line.Substring (line.IndexOf ("!") + 1));
|
||||||
|
|
||||||
this.socket.Send (ping_bytes);
|
if (!folder_identifier.Equals ("debug") &&
|
||||||
|
!String.IsNullOrEmpty (message)) {
|
||||||
|
|
||||||
if (this.socket.Receive (pong_bytes) < 1)
|
// We have a message!
|
||||||
// 10057 means "Socket is not connected"
|
OnAnnouncement (new SparkleAnnouncement (folder_identifier, message));
|
||||||
throw new SocketException (10057);
|
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("ListenerTcp", "Received pong from " + Server);
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
this.last_ping = DateTime.Now;
|
|
||||||
|
|
||||||
} else {
|
|
||||||
|
|
||||||
// Check when the last ping occured. If it's
|
|
||||||
// significantly longer than our regular interval the
|
|
||||||
// system likely woke up from sleep and we want to
|
|
||||||
// simulate a disconnect
|
|
||||||
int sleepiness = DateTime.Compare (
|
|
||||||
this.last_ping.AddMilliseconds (timeout * 1000 * 1.2),
|
|
||||||
DateTime.Now
|
|
||||||
);
|
|
||||||
|
|
||||||
if (sleepiness <= 0) {
|
|
||||||
SparkleHelpers.DebugInfo ("ListenerTcp", "System woke up from sleep");
|
|
||||||
|
|
||||||
// 10057 means "Socket is not connected"
|
|
||||||
throw new SocketException (10057);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The ping failed: disconnect completely
|
|
||||||
} catch (SocketException e) {
|
|
||||||
this.is_connected = false;
|
|
||||||
this.is_connecting = false;
|
|
||||||
|
|
||||||
if (this.socket != null) {
|
|
||||||
this.socket.Close ();
|
|
||||||
this.socket = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
OnDisconnected ("Ping timeout: " + e.Message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Thread.Sleep (1000);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (Exception) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (this.socket.Available > 0)
|
|
||||||
bytes_read = this.socket.Receive (bytes);
|
|
||||||
|
|
||||||
// Parse the received message
|
|
||||||
if (bytes_read > 0) {
|
|
||||||
string received = Encoding.UTF8.GetString (bytes);
|
|
||||||
string line = received.Substring (0, received.IndexOf ("\n"));
|
|
||||||
|
|
||||||
if (!line.Contains ("!"))
|
|
||||||
continue;
|
|
||||||
|
|
||||||
string folder_identifier = line.Substring (0, line.IndexOf ("!"));
|
|
||||||
string message = CleanMessage (line.Substring (line.IndexOf ("!") + 1));
|
|
||||||
|
|
||||||
if (!folder_identifier.Equals ("debug") &&
|
|
||||||
!String.IsNullOrEmpty (message)) {
|
|
||||||
|
|
||||||
// We have a message!
|
|
||||||
OnAnnouncement (new SparkleAnnouncement (folder_identifier, message));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
);
|
});
|
||||||
|
|
||||||
this.thread.Start ();
|
this.thread.Start ();
|
||||||
}
|
}
|
||||||
|
|
|
@ -154,11 +154,7 @@ namespace SparkleLib {
|
||||||
ChangeSets = GetChangeSets ();
|
ChangeSets = GetChangeSets ();
|
||||||
SparkleWatcherFactory.CreateWatcher (this);
|
SparkleWatcherFactory.CreateWatcher (this);
|
||||||
|
|
||||||
new Thread (
|
new Thread (() => CreateListener ()).Start ();
|
||||||
new ThreadStart (delegate {
|
|
||||||
CreateListener ();
|
|
||||||
})
|
|
||||||
).Start ();
|
|
||||||
|
|
||||||
this.remote_timer.Elapsed += delegate {
|
this.remote_timer.Elapsed += delegate {
|
||||||
bool time_to_poll = (DateTime.Compare (this.last_poll,
|
bool time_to_poll = (DateTime.Compare (this.last_poll,
|
||||||
|
@ -382,12 +378,11 @@ namespace SparkleLib {
|
||||||
if (this.listener.IsConnected) {
|
if (this.listener.IsConnected) {
|
||||||
this.poll_interval = PollInterval.Long;
|
this.poll_interval = PollInterval.Long;
|
||||||
|
|
||||||
new Thread (
|
new Thread (() => {
|
||||||
new ThreadStart (delegate {
|
if (!is_syncing && !HasLocalChanges && HasRemoteChanges)
|
||||||
if (!is_syncing && !HasLocalChanges && HasRemoteChanges)
|
SyncDownBase ();
|
||||||
SyncDownBase ();
|
|
||||||
})
|
}).Start ();
|
||||||
).Start ();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.listener.Connected += ListenerConnectedDelegate;
|
this.listener.Connected += ListenerConnectedDelegate;
|
||||||
|
|
|
@ -65,7 +65,7 @@ case $1 in
|
||||||
invite=`date -u +%N`
|
invite=`date -u +%N`
|
||||||
open=`echo $2 | sed s/sparkleshare:/https:/`
|
open=`echo $2 | sed s/sparkleshare:/https:/`
|
||||||
open=`echo $open | sed s/sparkleshare-unsafe:/http:/`
|
open=`echo $open | sed s/sparkleshare-unsafe:/http:/`
|
||||||
curl -o ~/SparkleShare/$invite.xml $open --insecure
|
curl --insecure --output ~/SparkleShare/$invite.xml $open
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
|
mono "@expanded_libdir@/@PACKAGE@/SparkleShare.exe" --help
|
||||||
|
|
Binary file not shown.
Loading…
Reference in a new issue