-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrouter.dart
49 lines (41 loc) · 1.07 KB
/
router.dart
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
import 'routing_components.dart';
abstract class RouterInterface {
bool resolve(String url);
void stream();
}
class Router implements RouterInterface {
ConnectionManager _connectionManager;
RoutingTable _table;
Firewall _firewall;
Router(this._connectionManager, this._table, this._firewall);
@override
bool resolve(String _url) {
Route? _route = _table.mapUrlToIPAddress(_url);
if (_route != null) {
_connect(_route.getIpAddress());
} else {
print("Route was not found.");
return false;
}
return true;
}
@override
void stream() {
List<String> _packets = [
'Package one is clean',
'Package two is clean',
'Package three is __BAD__',
'Package four is __BAD__',
];
for (String packet in _packets) {
if (_firewall.isValidPacket(packet)) {
print("$packet.");
} else {
print("Dropping a packet.");
}
}
_terminate();
}
void _terminate() => _connectionManager.terminate();
void _connect(String _ipAddress) => _connectionManager.connectTo(_ipAddress);
}