redirect method
Redirects connection to given proxy
.
Implementation
@override
Future<void> redirect(ProxySettings proxy) async {
final proxyClient = await SocksUDPClient.connect([proxy]);
final client = await accept();
client.transform(StreamTransformer<RawSocketEvent, SocksUpdPacket>.fromHandlers(
handleData: (event, sink) {
if(event != RawSocketEvent.read)
return;
final packet = client.receiveSocksPacket();
if(packet == null)
return;
sink.add(packet);
},
),).listen((packet) => proxyClient.send(packet.socksPacket, proxy.host, proxy.port));
proxyClient.transform(StreamTransformer<RawSocketEvent, SocksUpdPacket>.fromHandlers(
handleData: (event, sink) {
if(event != RawSocketEvent.read)
return;
final datagram = proxyClient.receive();
if(datagram == null)
return;
final packet = SocksUpdPacket.create(datagram.address, datagram.port, datagram.data);
sink.add(packet);
},
),).listen((packet) => proxyClient.send(packet.socksPacket, desiredAddress, desiredPort));
throw UnimplementedError();
}