Skip to content

Commit 9924d68

Browse files
author
blomman84
committed
* Hub has a new property called StoreId and should be used when creating a new Source.
* Hub has a new function called GetUserByStoredId, thanks hackward for suggesting it. * RemoteCertificateValidation has a new default behaivor to make it more simple for you as a developer. it will now auto approve certificate if you havn't showed that you have overriden the funtionality by setting CertificateValidationInfo.Handled to true. * Added functionality to UPnP to make it possible to specify search target * Changed what search target to use in UPnP Detect. Now used "urn:schemas-upnp-org:service:WANIPConnection:1". * Changed the method IEnumerator<KeyValuePair<string, ContentInfo>> GetEnumerator in Share to have the same output as the generic one. * Added Equals functionality on Source. * Added a IsReady Property and action to Hub that should tell you as a developer when the hub is ready to be sending commands/messages to. * All transfers now have a centrilized way of reading/writing/closing files (Should be better then before). You are encuraged to use this logic yourself. Logic is in here: FlowLib.Utils.FileOperations. - Changed how we allocate files. Thanks hackward for code. * Changed how we locked stuff in TransferManager. We will now just lock stuff we need to lock. * Changed so ADC users are passive until we know something else. * Changed some int.Parse to long.Parse (Then was stored as long, just not parsed as long). * Changed how parsing is done for ADC (Hopefully not broken anything). * Changed so we now use System.Net.IPEndPoint.MinPort and System.Net.IPEndPoint.MaxPort instead of hardcoded values. * Made it possible to get a C# class from a web address. For example: FlowLib.Utils.WebOperations<Version>.GetObjectFromPage("http://www.example.com/version.xml") would try to get a Xml representation of a class called Version. * Added some work for automated testing.
1 parent 8a791d0 commit 9924d68

File tree

291 files changed

+147300
-496
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

291 files changed

+147300
-496
lines changed

FlowLib/Connections/Hub.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -114,6 +114,16 @@ public override IShare Share
114114
}
115115
}
116116
}
117+
public string StoreId
118+
{
119+
get
120+
{
121+
if (HubSetting == null)
122+
return null;
123+
return HubSetting.Address + HubSetting.Port.ToString();
124+
}
125+
}
126+
117127
/// <summary>
118128
/// Settings used by this hub for connection.
119129
/// </summary>
@@ -345,7 +355,28 @@ public User GetUserByNick(string nick)
345355
return null;
346356
}
347357

348-
#region Connection
358+
/// <summary>
359+
/// Returns first user in userlist with the specified storedId.
360+
/// </summary>
361+
/// <param name="storedId">StoredId for the user we want to get</param>
362+
/// <returns>User that have the specified storedId or null if not found</returns>
363+
public User GetUserByStoredId(string storedId)
364+
{
365+
// TODO : Make this more effective.
366+
lock (userlist)
367+
{
368+
foreach (KeyValuePair<string, User> kpair in userlist)
369+
{
370+
if (storedId.Equals(kpair.Value.StoreID))
371+
{
372+
return kpair.Value;
373+
}
374+
}
375+
}
376+
return null;
377+
}
378+
379+
#region Connection
349380
/// <summary>
350381
/// Tells listener object that hub is will reconnect and then reconnects.
351382
/// </summary>

FlowLib/Connections/TcpConnection.cs

+19-7
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -39,6 +39,7 @@
3939
using System.Security.Cryptography.X509Certificates;
4040
using FlowLib.Containers.Security;
4141
using FlowLib.Enums;
42+
using System.IO;
4243
#endif
4344

4445
#if COMPACT_FRAMEWORK
@@ -195,7 +196,10 @@ protected void CheckSecure()
195196
{
196197
SecureUpdate(this, new FmdcEventArgs(Actions.SecurityAuthenticationError, pe));
197198
}
198-
199+
catch (IOException ioe)
200+
{
201+
SecureUpdate(this, new FmdcEventArgs(Actions.SecurityAuthenticationError, ioe));
202+
}
199203
}
200204
#endif
201205
public bool IsDisposed
@@ -427,7 +431,7 @@ public virtual void Disconnect(string msg)
427431
}
428432
#endif
429433

430-
socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger,new LingerOption(false, 0));
434+
//socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger,new LingerOption(false, 0));
431435
socket.Disconnect(true);
432436
}
433437
catch (Exception) { }
@@ -481,7 +485,7 @@ protected virtual void SetupRecieveCallback(Socket sock)
481485
{
482486
// Determin Protocol to use here.
483487
//if (Protocol != null && sock.Connected && first)
484-
if (Protocol != null && first && !importedSocket)
488+
if (first && !importedSocket && Protocol != null)
485489
{
486490
first = false;
487491
if (Protocol.FirstCommand != null)
@@ -740,9 +744,17 @@ protected bool OnRemoteCertificateValidation(
740744
FmdcEventArgs args = new FmdcEventArgs(Actions.SecurityValidateRemoteCertificate, info);
741745
SecureUpdate(this, args);
742746
info = args.Data as CertificateValidationInfo;
743-
if (info == null)
744-
return false;
745-
return info.Accepted;
747+
if (args.Handled)
748+
{
749+
if (info == null)
750+
return false;
751+
return info.Accepted;
752+
}
753+
else
754+
{
755+
// If developer havnt added logic to support this. Assume Accepted.
756+
return true;
757+
}
746758
}
747759

748760
protected X509Certificate OnLocalCertificateSelection(

FlowLib/Connections/UPnP.cs

+13-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -66,10 +66,12 @@ public System.Net.IPEndPoint EndPoint
6666
set;
6767
}
6868

69-
public UPnP() : this(null, null) { }
69+
public UPnP() : this(null, null, null) { }
7070
public UPnP(IPEndPoint point) : this(point, null) { }
7171
public UPnP(IBaseUpdater updater) : this(null, updater) { }
72-
public UPnP(IPEndPoint point, IBaseUpdater updater)
72+
public UPnP(IPEndPoint point, IBaseUpdater updater) : this(point, updater, null) { }
73+
public UPnP(IBaseUpdater updater, string searchTarget) : this(null, updater, searchTarget) { }
74+
public UPnP(IPEndPoint point, IBaseUpdater updater, string searchTarget)
7375
{
7476
RootDevices = new SortedList<string, UPnPDevice>();
7577
if (point == null)
@@ -82,7 +84,14 @@ public UPnP(IPEndPoint point, IBaseUpdater updater)
8284
}
8385
client = new Socket(AddressFamily.InterNetwork,
8486
SocketType.Dgram, ProtocolType.Udp);
85-
ProtocolUPnP = new UPnPProtocol(this);
87+
if (string.IsNullOrEmpty(searchTarget))
88+
{
89+
ProtocolUPnP = new UPnPProtocol(this);
90+
}
91+
else
92+
{
93+
ProtocolUPnP = new UPnPProtocol(this, searchTarget);
94+
}
8695
}
8796

8897
protected virtual void OnUpdateBase(object sender, FlowLib.Events.FmdcEventArgs e)
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System.IO;
2+
3+
namespace FlowLib.Containers
4+
{
5+
public class FileStreamContainer
6+
{
7+
public FileStream FileStream
8+
{
9+
get;
10+
set;
11+
}
12+
13+
public long LastAccessed
14+
{
15+
get;
16+
set;
17+
}
18+
}
19+
}

FlowLib/Containers/Share.cs

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -1353,9 +1353,26 @@ protected void OnErrorOccured(object sender, FmdcEventArgs e)
13531353
//public IEnumerator<KeyValuePair<string, ContentInfo>> GetEnumerator()
13541354
IEnumerator<KeyValuePair<string, ContentInfo>> IEnumerable<KeyValuePair<string, ContentInfo>>.GetEnumerator()
13551355
{
1356-
lock (share)
1356+
if (share.Count != 0)
1357+
{
1358+
lock (share)
1359+
{
1360+
return share.GetEnumerator();
1361+
}
1362+
}
1363+
else if (tthNames.Count != 0)
1364+
{
1365+
lock (tthNames)
1366+
{
1367+
return tthNames.GetEnumerator();
1368+
}
1369+
}
1370+
else
13571371
{
1358-
return share.GetEnumerator();
1372+
lock (virtualNames)
1373+
{
1374+
return virtualNames.GetEnumerator();
1375+
}
13591376
}
13601377
}
13611378
#endregion

FlowLib/Containers/Source.cs

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -29,7 +29,8 @@ namespace FlowLib.Containers
2929
public class Source
3030
: System.Collections.Generic.IComparer<Source>,
3131
System.Collections.IComparer,
32-
System.IComparable
32+
System.IComparable,
33+
System.Collections.Generic.IEqualityComparer<Source>
3334
{
3435
protected string conId = string.Empty;
3536
protected string userId = string.Empty;
@@ -152,5 +153,15 @@ public int CompareTo(object obj)
152153
return this.Compare(this, obj);
153154
}
154155
#endregion
155-
}
156+
157+
public bool Equals(Source x, Source y)
158+
{
159+
return Compare(x, y) == 0;
160+
}
161+
162+
public int GetHashCode(Source obj)
163+
{
164+
return base.GetHashCode();
165+
}
166+
}
156167
}

FlowLib/Containers/TransferRequest.cs

+20-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -26,11 +26,12 @@ namespace FlowLib.Containers
2626
{
2727
public class TransferRequest
2828
{
29-
UserInfo user = null;
30-
Hub hub = null;
31-
IShare share = null;
32-
string key = null;
29+
UserInfo user;
30+
Hub hub;
31+
IShare share;
32+
string key;
3333
int meDownload = -1; // Not set (We dont know who is going to download)
34+
Source _source;
3435

3536
public bool Download
3637
{
@@ -52,12 +53,16 @@ public Source Source
5253
{
5354
get
5455
{
55-
string conId = null;
56-
if (hub != null || hub.HubSetting != null)
56+
if (_source == null)
5757
{
58-
conId = hub.HubSetting.Address + hub.HubSetting.Port;
58+
string conId = null;
59+
if (hub != null || hub.HubSetting != null)
60+
{
61+
conId = hub.StoreId;
62+
}
63+
_source = new Source(conId, user.StoreID);
5964
}
60-
return new Source(conId, user.StoreID);
65+
return _source;
6166
}
6267
}
6368

@@ -104,6 +109,12 @@ public TransferRequest(string pKey, Hub pHub, UserInfo pUser, bool download)
104109
meDownload = 0;
105110
}
106111

112+
public TransferRequest(Source src)
113+
: this(src.UserId, null, null)
114+
{
115+
_source = src;
116+
}
117+
107118
/// <summary>
108119
/// Creates a Transfer request
109120
/// </summary>

FlowLib/Containers/UPnP/UPnPFunction.cs

+23-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
/*
33
*
4-
* Copyright (C) 2009 Mattias Blomqvist, patr-blo at dsv dot su dot se
4+
* Copyright (C) 2010 Mattias Blomqvist, patr-blo at dsv dot su dot se
55
*
66
* This program is free software; you can redistribute it and/or modify
77
* it under the terms of the GNU General Public License as published by
@@ -20,6 +20,7 @@
2020
*/
2121

2222
using System.Collections.Generic;
23+
using System.Text;
2324

2425
namespace FlowLib.Containers.UPnP
2526
{
@@ -57,5 +58,26 @@ public UPnPFunction()
5758
Arguments = new SortedList<string, string>();
5859
ErrorCode = 0;
5960
}
61+
62+
public override string ToString()
63+
{
64+
StringBuilder sb = new StringBuilder();
65+
if (Service != null && Service.Device != null && Service.Device.Information != null)
66+
{
67+
sb.Append("Device: ");
68+
sb.Append(Service.Device.Information.Sender);
69+
sb.Append(" (");
70+
sb.Append(Service.Device.Information.DeviceType);
71+
sb.AppendLine(")");
72+
}
73+
sb.Append(Name);
74+
sb.AppendLine("(");
75+
foreach (KeyValuePair<string, string> item in Arguments)
76+
{
77+
sb.AppendFormat("\t{0} = {1}\r\n", item.Key, item.Value);
78+
}
79+
sb.AppendLine(")");
80+
return sb.ToString();
81+
}
6082
}
6183
}

0 commit comments

Comments
 (0)