text
stringlengths
0
234
accept set_params (slave_params : SlaveParams) do
params := slave_params;
Function Definition: procedure Parse_Command_Line;
Function Body: procedure Print_Help;
procedure Increment_Total (Ignore : Ada.Directories.Directory_Entry_Type);
procedure Each_Torrents
(Dir : League.Strings.Universal_String;
Proc : not null access procedure
(Item : Ada.Directories.Directory_Entry_Type));
Cmd : constant League.String_Vectors.Universal_String_Vector :=
League.Application.Arguments;
Log_Option : constant Wide_Wide_String := "--log=";
Out_Option : constant Wide_Wide_String := "--output=";
Dir_Option : constant Wide_Wide_String := "--torrent-dir=";
Port_Option : constant Wide_Wide_String := "--port=";
Help_Option : constant Wide_Wide_String := "--help";
Port : Positive := 33411;
Path : League.Strings.Universal_String := +"result";
Input_Path : League.Strings.Universal_String := +"torrents";
Total : Ada.Containers.Count_Type := 0;
procedure Set_Peer_Id (Value : out SHA1);
-----------------
-- Set_Peer_Id --
-----------------
procedure Set_Peer_Id (Value : out SHA1) is
Settings : League.Settings.Settings;
Context : GNAT.SHA1.Context;
Element : League.Strings.Universal_String;
Vector : League.Stream_Element_Vectors.Stream_Element_Vector;
Key : constant League.Strings.Universal_String := +"torrent/peer_id";
Now : constant String := Ada.Calendar.Formatting.Image
(Ada.Calendar.Clock);
begin
if Settings.Contains (Key) then
Element := League.Holders.Element (Settings.Value (Key));
Vector := League.Base_Codecs.From_Base_64 (Element);
Value := Vector.To_Stream_Element_Array;
else
GNAT.SHA1.Update (Context, Path.To_UTF_8_String);
GNAT.SHA1.Update (Context, Now);
GNAT.SHA1.Update (Context, GNAT.Sockets.Host_Name);
Value := GNAT.SHA1.Digest (Context);
Vector.Append (Value);
Element := League.Base_Codecs.To_Base_64 (Vector);
Settings.Set_Value (Key, League.Holders.To_Holder (Element));
end if;
end Set_Peer_Id;
---------------------
-- Increment_Total --
---------------------
procedure Increment_Total (Ignore : Ada.Directories.Directory_Entry_Type) is
use type Ada.Containers.Count_Type;
begin
Total := Total + 1;
end Increment_Total;
-------------------
-- Each_Torrents --
-------------------
procedure Each_Torrents
(Dir : League.Strings.Universal_String;
Proc : not null access procedure
(Item : Ada.Directories.Directory_Entry_Type))
is
begin
Ada.Directories.Search
(Directory => Dir.To_UTF_8_String,
Pattern => "*.torrent",
Filter => (Ada.Directories.Ordinary_File => True, others => False),
Process => Proc);
end Each_Torrents;
------------------------
-- Parse_Command_Line --
------------------------
procedure Parse_Command_Line is
Arg : League.Strings.Universal_String;
begin
for J in 1 .. Cmd.Length loop
Arg := Cmd.Element (J);
if Arg.Starts_With (Port_Option) then
Port := Positive'Wide_Wide_Value
(Arg.Tail_From (Port_Option'Length + 1).To_Wide_Wide_String);