text stringlengths 0 234 |
|---|
-- Hash -- |
---------- |
function Hash (Item : Torrent.Connections.Connection_Access) |
return Ada.Containers.Hash_Type is |
begin |
return Ada.Containers.Hash_Type'Mod (+Item); |
end Hash; |
---------- |
-- Less -- |
---------- |
function Less (Left, Right : Planned_Connection) return Boolean is |
use type Ada.Calendar.Time; |
function "+" (V : GNAT.Sockets.Sock_Addr_Type) return String |
renames GNAT.Sockets.Image; |
begin |
return Left.Time < Right.Time |
or else (Left.Time = Right.Time and +Left.Addr < +Right.Addr); |
end Less; |
-------------------- |
-- Read_Handshake -- |
-------------------- |
procedure Read_Handshake (Item : in out Accepted_Connection) is |
use Torrent.Handshakes; |
use type Ada.Streams.Stream_Element; |
Last : Ada.Streams.Stream_Element_Count; |
Job : Torrent.Downloaders.Downloader_Access; |
begin |
GNAT.Sockets.Receive_Socket |
(Item.Socket, |
Item.Data (Item.Last + 1 .. Item.Data'Last), |
Last); |
if Last <= Item.Last then |
Item.Done := True; -- Connection closed |
elsif Last = Item.Data'Last then |
declare |
Value : constant Handshake_Type := -Item.Data; |
begin |
Job := Context.Find_Download (Value.Info_Hash); |
Item.Done := True; |
if Value.Length = Header'Length |
and then Value.Head = Header |
and then Job not in null |
then |
Item.Session := Job.Create_Session (Item.Address); |
Item.Session.Do_Handshake |
(Item.Socket, Job.Completed, Inbound => True); |
end if; |
Function Definition: procedure Check_Intrested; |
Function Body: procedure Send_Initial_Requests; |
function Get_Handshake |
(Data : Ada.Streams.Stream_Element_Array) return Boolean; |
function Get_Length |
(Data : Ada.Streams.Stream_Element_Array) |
return Ada.Streams.Stream_Element_Offset; |
procedure Read_Messages |
(Data : in out Ada.Streams.Stream_Element_Array; |
Last : out Ada.Streams.Stream_Element_Count); |
procedure On_Message (Data : Ada.Streams.Stream_Element_Array); |
procedure Save_Piece |
(Index : Piece_Index; |
Offset : Natural; |
Data : Ada.Streams.Stream_Element_Array); |
--------------------- |
-- Check_Intrested -- |
--------------------- |
procedure Check_Intrested is |
begin |
if not Self.We_Intrested |
and then Self.Listener.We_Are_Intrested (Self.Piece_Map) |
then |
Self.Send_Message ((00, 00, 00, 01, 02)); -- interested |
Self.We_Intrested := True; |
end if; |
end Check_Intrested; |
------------------- |
-- Get_Handshake -- |
------------------- |
function Get_Handshake |
(Data : Ada.Streams.Stream_Element_Array) return Boolean |
is |
function "+" is new Ada.Unchecked_Conversion |
(Handshake_Image, Handshake_Type); |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.