add a check for allowIncommingParents

add some extra information about parents
This commit is contained in:
cheatengine@gmail.com 2014-10-16 11:36:19 +00:00
parent c3643c7f08
commit 5ebd3995a0
5 changed files with 136 additions and 58 deletions

View File

@ -155,7 +155,6 @@ begin
else
if pictureformat=3 then
begin
fpi:=TFPMemoryImage.Create(0,0);
fpr:=TFPReaderPNG.create;
fpi.LoadFromStream(f, fpr);

View File

@ -87,6 +87,7 @@ type
childnodes: array of TPointerscanControllerChild;
parentUpdater: TAsyncTimer;
lastUpdateSent: integer;
lastPathCheck: qword; //last time the path check checked the queues
@ -380,6 +381,7 @@ type
function getTotalThreadCount: integer;
procedure getConnectingList(var l: TConnectEntryArray);
procedure getConnectionList(var l: TConnectionEntryArray);
procedure getParentData(var d: TPublicParentData);
procedure TerminateAndSaveState;
procedure execute; override;
@ -1178,6 +1180,16 @@ begin
setlength(l,0);
end;
procedure TPointerscanController.getParentData(var d: TPublicParentData);
begin
d.connected:=parent.socket<>nil;
d.ip:=parent.ip;
d.port:=parent.port;
d.lastupdatesent:=lastUpdateSent;
d.waitingforreconnect:=orphanedSince<>0;
end;
procedure TPointerscanController.appendDynamicPathQueueToOverflowQueue(paths: TDynPathQueue);
var oldstart: integer;
i: integer;
@ -2962,12 +2974,18 @@ begin
if connectiontype=0 then //parent
begin
if not allowIncomingParent then
raise exception.create('A parent tried to connect');
if parentpassword<>password then
raise TSocketException.create('Invalid parent password');
end
else
if connectiontype=1 then //child
begin
if not allowIncomingChildren then
raise exception.create('A child tried to connect');
if childpassword<>password then
raise TSocketException.create('Invalid child password');
end
@ -4022,6 +4040,8 @@ begin
parent.socket.WriteBuffer(updatemsg, sizeof(updatemsg));
parent.socket.flushWrites;
lastUpdateSent:=GetTickCount64;
HandleUpdateStatusReply;
end
else
@ -4692,6 +4712,7 @@ begin
else
begin
//this wants to be a parent
parentcs.Enter;
try
//add it to the queue
@ -4715,6 +4736,16 @@ begin
else
parentqueue[length(parentqueue)-1].iConnectedTo:=false;
len:=sizeof(ipname);
if getpeername(sockethandle, ipname, len)<>SOCKET_ERROR then
begin
parentqueue[length(parentqueue)-1].ip:=inttostr(byte(ipname.sin_addr.S_un_b.s_b1))+'.'+inttostr(byte(ipname.sin_addr.S_un_b.s_b2))+
inttostr(byte(ipname.sin_addr.S_un_b.s_b3))+'.'+inttostr(byte(ipname.sin_addr.S_un_b.s_b4));
parentqueue[length(parentqueue)-1].port:=ipname.sin_port;
end;
//you have a new daddy! Say hello to him

View File

@ -295,6 +295,12 @@ type
network: record
node: TTreenode; // + network
parent: TTreenode; //ip+port or disconnected
parentnodes: record
lastUpdateSent: TTreenode;
end;
connectingto: TTreenode;
connectingToNodes: array of record
data: TTreenode; //ip, port, trusted
@ -1227,7 +1233,7 @@ begin
staticscanner.Start;
pnlData.Visible:=true;
timer2.enabled:=true;
end;
@ -1594,6 +1600,7 @@ var i,j: integer;
connectinglist: TConnectEntryArray;
connectionlist: TConnectionEntryArray;
parentdata: TPublicParentData;
info: tstringlist;
@ -1744,9 +1751,7 @@ begin
infonodes.network.connectingToNodes[i].data.Free;
setlength(infonodes.network.connectingToNodes, length(connectinglist));
if length(connectinglist)>0 then
begin
//connecting to:
if infonodes.network.connectingto=nil then
infonodes.network.connectingto:=tvInfo.Items.AddChild(infonodes.network.node,'Connecting to:');
@ -1764,7 +1769,7 @@ begin
infonodes.network.connectingToNodes[i].data.Text:=s;
end;
end;
staticscanner.getConnectionList(connectionlist);
@ -1774,10 +1779,41 @@ begin
setlength(infonodes.network.connectedToNodes, length(connectionlist));
if length(connectionlist)>0 then
//connected to:
if Staticscanner.initializer=false then
begin
staticscanner.getParentData(parentdata);
if infonodes.network.parent=nil then
infonodes.network.parent:=tvInfo.Items.AddChild(infonodes.network.node,'Parent: ');
if parentdata.connected then
begin
infonodes.network.parent.Text:='Parent: '+parentdata.ip+':'+inttostr(parentdata.port);
if infonodes.network.parentnodes.lastUpdateSent=nil then
infonodes.network.parentnodes.lastUpdateSent:=tvInfo.Items.AddChild(infonodes.network.parent,'');
infonodes.network.parentnodes.lastUpdateSent.Text:=inttostr(GetTickCount64-parentdata.lastupdatesent div 1000)+' seconds ago';
end
else
begin
//mark that it has no parent (yet/anymore)
if parentdata.waitingforreconnect then
infonodes.network.parent.Text:='Parent: <disconnected> (Waiting for reconnect)'
else
infonodes.network.parent.Text:='Parent: <none>';
//if there are nodes, delete them
if infonodes.network.parentnodes.lastUpdateSent<>nil then
freeandnil(infonodes.network.parentnodes.lastUpdateSent);
end;
end;
if infonodes.network.connectedTo=nil then
infonodes.network.connectedTo:=tvInfo.Items.AddChild(infonodes.network.node,'Connected to:');
infonodes.network.connectedTo:=tvInfo.Items.AddChild(infonodes.network.node,'Children:');
for i:=0 to length(connectionlist)-1 do
begin
@ -1828,8 +1864,10 @@ begin
//pathspersecond.text:='Paths/second: '+inttostr(connectionlist[i].pathspersecond);
end;
end;
end;
end;
end;

View File

@ -12,6 +12,14 @@ uses
Classes, SysUtils;
type
TPublicParentData=record
connected: boolean;
ip: string;
port: word;
lastupdatesent: qword;
waitingforreconnect: boolean;
end;
TPublicConnectionEntry=record //information publicly available about children
parentconnectedto: boolean; //true if the parent connected to the child
ip: string;

View File

@ -37,6 +37,8 @@ type
port: word;
password: string;
end;
ip: string;
port: word;
trustsme: boolean;
end;