aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/netliba/v6/udp_client_server.h
blob: 23e0209405c32048e00dc2dd6558d929debc0d7e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#pragma once

#include <util/generic/ptr.h>
#include <util/generic/guid.h>
#include <library/cpp/netliba/socket/socket.h>

#include "udp_address.h"
#include "net_request.h"

namespace NNetliba {
    class TRopeDataPacket;
    struct TRequesterPendingDataStats;
    struct IPeerQueueStats;

    struct TSendResult {
        int TransferId;
        bool Success;
        TSendResult()
            : TransferId(-1)
            , Success(false)
        {
        }
        TSendResult(int transferId, bool success)
            : TransferId(transferId)
            , Success(success)
        {
        }
    };

    enum EPacketPriority {
        PP_LOW,
        PP_NORMAL,
        PP_HIGH
    };

    // Step should be called from one and the same thread
    // thread safety is caller responsibility
    struct IUdpHost: public TThrRefBase {
        virtual TRequest* GetRequest() = 0;
        // returns trasferId
        // Send() needs correctly computed crc32
        // crc32 is expected to be computed outside of the thread talking to IUdpHost to avoid crc32 computation delays
        // packetGuid provides packet guid, if packetGuid is empty then guid is generated
        virtual int Send(const TUdpAddress& addr, TAutoPtr<TRopeDataPacket> data, int crc32, TGUID* packetGuid, EPacketPriority pp) = 0;
        virtual bool GetSendResult(TSendResult* res) = 0;
        virtual void Step() = 0;
        virtual void IBStep() = 0;
        virtual void Wait(float seconds) = 0; // does not use UdpHost
        virtual void CancelWait() = 0;        // thread safe
        virtual void GetPendingDataSize(TRequesterPendingDataStats* res) = 0;
        virtual TString GetDebugInfo() = 0;
        virtual void Kill(const TUdpAddress& addr) = 0;
        virtual TIntrusivePtr<IPeerQueueStats> GetQueueStats(const TUdpAddress& addr) = 0;
    };

    TIntrusivePtr<IUdpHost> CreateUdpHost(int port);
    TIntrusivePtr<IUdpHost> CreateUdpHost(const TIntrusivePtr<NNetlibaSocket::ISocket>& socket);

    void SetUdpMaxBandwidthPerIP(float f);
    void SetUdpSlowStart(bool enable);
    void DisableIBDetection();
}