File size: 3,550 Bytes
c7c0a38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183

from __future__ import annotations 
from dataclasses import dataclass ,field ,asdict 
from typing import Optional ,List ,Dict ,Any 
import json 
import time 






TRANSPORT_TYPES =["tcp","grpc"]


CANDIDATE_PORTS =[443 ,80 ,8443 ,2053 ,2083 ,2087 ,9443 ]


SNI_DOMAINS =[

"download.nvidia.com",
"swscan.apple.com",
"updates.cdn-apple.com",
"steamcdn-a.akamaihd.net",
"dl.delivery.mp.microsoft.com",
"download.windowsupdate.com",
"cdn.cloudflare.steamstatic.com",
"origin-a.akamaihd.net",
"pkg-containers.githubusercontent.com",
"download.jetbrains.com",
"packages.ubuntu.com",

"ajax.aspnetcdn.com",
"github-releases.githubusercontent.com",
"objects.githubusercontent.com",
"software.download.prss.microsoft.com",



]

FINGERPRINTS =["chrome","firefox","edge","safari","ios","random","randomized"]


ALPN_OPTIONS =[
["h2","http/1.1"],
["h2"],
["http/1.1"],
]

FRAGMENT_STRATEGIES =["none","tlshello","all"]

MUX_CONCURRENCY_VALUES =[0 ,1 ,2 ,4 ,8 ,16 ,32 ]

SHORT_ID_LENGTHS =[4 ,8 ,16 ]

XHTTP_MODES =["packet-up","streaming"]






@dataclass 
class VlessConfig :

    transport_type :str ="tcp"
    proxy_port :int =443 


    dest_domain :str ="download.nvidia.com"
    short_id :str ="abcdef01"
    spider_x :str ="/"


    fingerprint :str ="chrome"
    alpn :List [str ]=field (default_factory =lambda :["h2","http/1.1"])


    grpc_service_name :str ="grpc"
    xhttp_mode :str ="packet-up"


    fragment_strategy :str ="none"
    fragment_length_min :int =50 
    fragment_length_max :int =100 
    fragment_interval_min :int =1 
    fragment_interval_max :int =5 


    padding_enabled :bool =False 
    padding_min :int =0 
    padding_max :int =0 


    mux_concurrency :int =0 


    extra_headers :Dict [str ,str ]=field (default_factory =dict )

    def to_dict (self )->dict :
        return asdict (self )

    @classmethod 
    def from_dict (cls ,d :dict )->"VlessConfig":
        return cls (**d )

    def to_json (self )->str :
        return json .dumps (self .to_dict ())

    @classmethod 
    def from_json (cls ,s :str )->"VlessConfig":
        return cls .from_dict (json .loads (s ))






@dataclass 
class EpisodeMetrics :
    episode_id :str =""
    timestamp :float =field (default_factory =time .time )


    connected :bool =False 
    connect_time_ms :float =0.0 


    stability_ratio :float =0.0 
    reconnect_count :int =0 
    drop_count :int =0 


    throughput_mbps :float =0.0 
    throughput_ratio :float =0.0 


    avg_ping_ms :float =0.0 
    max_ping_ms :float =0.0 
    packet_loss_ratio :float =0.0 


    error_message :Optional [str ]=None 
    samples :int =0 

    def to_dict (self )->dict :
        return asdict (self )

    @classmethod 
    def from_dict (cls ,d :dict )->"EpisodeMetrics":
        return cls (**d )






@dataclass 
class EpisodeCommand :
    episode_id :str =""
    config :Optional [dict ]=None 
    duration_seconds :int =90 
    server_ip :str =""
    server_port :int =443 
    uuid :str =""

    def to_dict (self )->dict :
        return asdict (self )

    @classmethod 
    def from_dict (cls ,d :dict )->"EpisodeCommand":
        obj =cls (**{k :v for k ,v in d .items ()if k !="config"})
        obj .config =d .get ("config")
        return obj 


@dataclass 
class ClientStatus :
    episode_id :str =""
    partial_metrics :Optional [dict ]=None 
    phase :str ="idle"