79 lines
2.1 KiB
Markdown
79 lines
2.1 KiB
Markdown
# TODO:
|
|
- listen and connect for UDP
|
|
```js
|
|
listener {
|
|
mainsock = new UdpSocket(true)
|
|
mainsock.bind(in_end)
|
|
|
|
do {
|
|
pac = mainsock.receiveAny(out sender_end)
|
|
} while (pac is not ConnectionRequest) skip package
|
|
connector_end = sender_end
|
|
mainsock.sendTo(ConnectionConfirmation, connector_end)
|
|
|
|
attemptN = 0
|
|
while(attemptN < 20){
|
|
try {
|
|
pac = mainsock.receiveAny(out sender_end)
|
|
if(sender_end == connector_end) {
|
|
connector_pac = new ConnectorPackage.parse(pac)
|
|
mainsock.sendTo(connector_pac.data, connector_pac.destination),
|
|
}
|
|
else {
|
|
extern_pac = new ExternPackage(pac, sender_end)
|
|
mainsock.sendTo(extern_pac, connector_end)
|
|
}
|
|
attemptN = 0
|
|
}
|
|
catch {
|
|
attemptN++
|
|
sleep(10ms)
|
|
}
|
|
}
|
|
log("connector is unreachable")
|
|
}
|
|
|
|
connector {
|
|
if(output_mode == bind) {
|
|
mainsock = new UdpSocket(true)
|
|
mainsock.bind(out_end)
|
|
}
|
|
else if(output_mode == send) {
|
|
mainsock = new UdpSocket(false)
|
|
}
|
|
else throw
|
|
|
|
attemptN = 0
|
|
while(attemptN < 20) {
|
|
try {
|
|
pac = mainsock.receiveAny(out sender_end)
|
|
if(sender_end == out_end) {
|
|
connector_pac = new ConnectorPackage(pac)
|
|
}
|
|
else {
|
|
extern_pac = ExternPackage.parse(pac)
|
|
mainsock.sendTo(extern_pac.data, out_end)
|
|
}
|
|
attemptN = 0
|
|
}
|
|
catch {
|
|
attemptN++
|
|
sleep(10ms)
|
|
}
|
|
}
|
|
log("connector is unreachable")
|
|
}
|
|
|
|
```
|
|
- listen and connect for TCP
|
|
```js
|
|
|
|
```
|
|
|
|
- encrypt/decrypt input/output
|
|
- generate temp password from key every 10 minutes:
|
|
```js
|
|
rng(seed: time()/(10*60*CLOCKS_PER_SECOND), salt: hash(key))
|
|
```
|
|
|