-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Communicator: refactoring, cleaning and unification (Serg-Norseman/GE…
- Loading branch information
1 parent
d9436a0
commit c3e6f9c
Showing
51 changed files
with
1,242 additions
and
1,237 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
/* | ||
* "GKCommunicator", the chat and bulletin board of the genealogical network. | ||
* Copyright (C) 2018 by Sergey V. Zhdanovskih. | ||
* | ||
* This file is part of "GEDKeeper". | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System.Drawing; | ||
using System.IO; | ||
using System.Net; | ||
using System.Windows.Forms; | ||
using GKNet.Core; | ||
using GKNet.DHT; | ||
using GKNet.Protocol; | ||
|
||
namespace GKSimpleChat | ||
{ | ||
public partial class DHTLogDlg : Form, ILogger | ||
{ | ||
private DHTClient fDHTClient; | ||
|
||
public DHTLogDlg() | ||
{ | ||
InitializeComponent(); | ||
|
||
int port = DHTClient.PublicDHTPort; | ||
fDHTClient = new DHTClient(IPAddress.Any, port, this); | ||
fDHTClient.PeersFound += delegate (object sender, PeersFoundEventArgs e) { | ||
WriteLog(string.Format("Found peers: {0}", e.Peers.Count)); | ||
WriteLog(string.Format("Peers[0]: {0}", e.Peers[0].ToString())); | ||
}; | ||
} | ||
|
||
private void DHTLogDlg_Load(object sender, System.EventArgs e) | ||
{ | ||
var snkInfoHash = ProtocolHelper.CreateSignInfoKey(); | ||
WriteLog("Search for: " + snkInfoHash.ToHexString()); | ||
|
||
fDHTClient.Run(); | ||
fDHTClient.JoinNetwork(); | ||
fDHTClient.SearchNodes(snkInfoHash); | ||
} | ||
|
||
private void DHTLogDlg_FormClosed(object sender, FormClosedEventArgs e) | ||
{ | ||
fDHTClient.StopSearch(); | ||
} | ||
|
||
public void WriteLog(string str, bool display = true) | ||
{ | ||
Invoke((MethodInvoker)delegate { | ||
rtbLog.AppendText(str + "\r\n"); | ||
}); | ||
|
||
var fswriter = new StreamWriter(new FileStream("./dht.log", FileMode.Append)); | ||
fswriter.WriteLine(str); | ||
fswriter.Flush(); | ||
fswriter.Close(); | ||
} | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
TCPChatTest/Form1.Designer.cs → GKCommunicatorApp/Form1.Designer.cs
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* "GKCommunicator", the chat and bulletin board of the genealogical network. | ||
* Copyright (C) 2018 by Sergey V. Zhdanovskih. | ||
* | ||
* This file is part of "GEDKeeper". | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
using System; | ||
using System.Net; | ||
using System.Text; | ||
using System.Windows.Forms; | ||
using GKNet.Protocol; | ||
using GKNet.TCP; | ||
|
||
namespace GKSimpleChat | ||
{ | ||
public partial class Form1 : Form | ||
{ | ||
private TCPDuplexClient fClient; | ||
|
||
public Form1() | ||
{ | ||
InitializeComponent(); | ||
} | ||
|
||
private void btnConnect_Click(object sender, EventArgs e) | ||
{ | ||
fClient = new TCPDuplexClient(); | ||
fClient.DataReceive += RaiseDataReceive; | ||
fClient.Start(int.Parse(txtLocalPort.Text)); | ||
|
||
txtLocalPort.Enabled = false; | ||
btnConnect.Enabled = false; | ||
} | ||
|
||
private void btnSend_Click(object sender, EventArgs e) | ||
{ | ||
//var endPoint = new IPEndPoint(IPAddress.Parse(txtRemoteAddress.Text), int.Parse(txtRemotePort.Text)); | ||
//fClient.Send(endPoint, txtMsg.Text); | ||
SendHandshakeQuery(); | ||
} | ||
|
||
private void Form1_FormClosed(object sender, FormClosedEventArgs e) | ||
{ | ||
if (fClient != null) { | ||
fClient.Disconnect(); | ||
} | ||
} | ||
|
||
public void RaiseDataReceive(object sender, DataReceiveEventArgs e) | ||
{ | ||
Invoke((MethodInvoker)delegate { | ||
txtLog.Text += Encoding.UTF8.GetString(e.Data) + "\r\n"; | ||
}); | ||
} | ||
|
||
#region Protocol features | ||
|
||
private void SendHandshakeQuery() | ||
{ | ||
var data = ProtocolHelper.CreateHandshakeQuery(); | ||
var endPoint = new IPEndPoint(IPAddress.Parse(txtRemoteAddress.Text), int.Parse(txtRemotePort.Text)); | ||
var conn = fClient.GetConnection(endPoint); | ||
conn.Send(data); | ||
} | ||
|
||
#endregion | ||
} | ||
} |
Oops, something went wrong.