forked from maratishe/e2eprobe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrx.php
More file actions
202 lines (147 loc) · 4.98 KB
/
rx.php
File metadata and controls
202 lines (147 loc) · 4.98 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
<?php
set_time_limit(0);
ob_implicit_flush(1);
// Load ajaxkit
for ($prefix = is_dir('ajaxkit') ? 'ajaxkit/' : '';
!is_dir($prefix) && count(explode('/', $prefix)) < 4;
$prefix .= '../');
if (!is_file($prefix . "env.php")) $prefix = '/web/ajaxkit/';
if (!is_file($prefix . "env.php"))
die("\nERROR! Cannot find env.php in [$prefix]\n\n");
foreach (array('functions', 'env') as $k)
require_once($prefix . "$k.php");
clinit();
clhelp("PURPOSE: TCP receiver for e2eprobe");
clhelp("NOTE: uses port+1 for UDP probing");
htg(clget('port,wdir'));
$port2 = $port + 1;
echo "\n\n";
$lastime = tsystem();
$setup = null;
class MyServer extends NTCPServer {
public function eachloop($client) {
global $lastime, $setup, $wdir;
if (tsystem() - $lastime < 1) return;
$lastime = tsystem();
if (!$setup) return;
extract($setup);
// wait if probe still running
if (procpid('probe.udp')) return;
// no file → throughput = 0
if (!is_file("$wdir/temp.hcsv")) {
$setup = null;
echo "SENDING FINAL RESPONSE (no data)\n";
$client->send(array(
'msg' => 'ok',
'status' => 'done',
'thru' => 0
));
return;
}
// read probe output
$h = $setup;
$h['probe'] = array();
$lines = file("$wdir/temp.hcsv");
foreach ($lines as $line) {
$line = trim($line);
if (!$line) continue;
$h2 = tth($line);
if (!isset($h2['pos'])) continue;
extract($h2);
$h['probe'][$pos] = $pspace;
}
ksort($h['probe']);
$h['probe'] = hv($h['probe']);
// write result to bz64jsonl
$out = foutopen("$wdir/$tag.bz64jsonl", 'a');
foutwrite($out, $h);
foutclose($out);
echo "WROTE RESULT TO $wdir/$tag.bz64jsonl\n";
// compute throughput
$vs = $h['probe'];
$valid = array();
foreach ($vs as $v) {
if ($v != -1) lpush($valid, $v);
}
$thru = 0;
if (count($valid) && msum($valid) > 0) {
$thru = round(
0.001 * (($psize * 8 * count($valid)) /
(0.000001 * msum($valid)))
);
}
echo "SENDING FINAL RESPONSE (JSON)\n";
// ✅ FIX: send structured JSON
$client->send(array(
'msg' => 'ok',
'status' => 'done',
'thru' => $thru
));
echo "FINAL RESPONSE SENT\n";
$setup = null;
`rm -Rf $wdir/temp.hcsv`;
}
public function receive($h, $client) {
global $port2, $wdir, $setup, $lastime;
echo "CONTROL MESSAGE RECEIVED\n";
var_dump($h);
$params = array();
if (is_array($h)) {
$params = $h;
} else {
$parts = explode(',', trim($h));
foreach ($parts as $p) {
$kv = explode('=', trim($p), 2);
if (count($kv) == 2)
$params[trim($kv[0])] = trim($kv[1]);
}
}
$method = isset($params['method']) ? $params['method'] : null;
// restart — die so rx.run.php restarts with clean state
if (isset($params['action']) && $params['action'] == 'restart') {
echo "RESTART RECEIVED — exiting\n";
die("\n");
}
$setup = $params;
extract($params);
// kill previous probe
if (procpid('probe.udp')) {
prockill(procpid('probe.udp'));
}
// PATHCHIRP
if ($method === 'pathchirp') {
$psize = isset($params['psize']) ? $params['psize'] : 1200;
$probesize = isset($params['probesize']) ? $params['probesize'] : 60;
$cmd = "$wdir/probe.udp.pathchirp.rx $port2 $wdir/temp.hcsv $psize $probesize";
echo "PATHCHIRP CMD: $cmd\n";
`rm -Rf $wdir/temp.hcsv`;
exec($cmd . ' > /dev/null 2>&1 &');
$lastime = tsystem();
$client->send(array('status' => 'ok'));
echo "ACK SENT\n";
fflush(STDOUT);
return;
}
// IGI / PROPOSED
if ($method === 'igi' || $method === 'proposed') {
$psize = isset($params['psize']) ? $params['psize'] : 1200;
$probesize = isset($params['probesize']) ? $params['probesize'] : 60;
$cmd = "$wdir/probe.udp.$method.rx $port2 $wdir/temp.hcsv $psize $probesize";
echo "CMD: $cmd\n";
`rm -Rf $wdir/temp.hcsv`;
exec($cmd . ' > /dev/null 2>&1 &');
$lastime = tsystem();
$client->send(array('status' => 'ok'));
echo "ACK SENT\n";
fflush(STDOUT);
return;
}
// fallback
$client->send(array('status' => 'ok'));
echo "FALLBACK ACK SENT\n";
fflush(STDOUT);
}
}
$S = new MyServer();
$S->start($port, true, 10000, 30);
?>