forked from scionproto/scion
-
Notifications
You must be signed in to change notification settings - Fork 1
/
msg_meta.py
103 lines (85 loc) · 2.57 KB
/
msg_meta.py
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
# Copyright 2016 ETH Zurich
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""
:mod:`msg_meta` --- Message Metadata
====================================
"""
from lib.packet.scion_addr import SCIONAddr
class MetadataBase(object):
"""
Base class for message metadata
"""
def __init__(self):
self.ia = None
self.host = None
self.path = None # Ready for sending (i.e., in correct direction)
self.port = 0
self.ext_hdr = ()
@classmethod
def from_values(cls, ia=None, host=None, path=None, ext_hdrs=(), port=0):
inst = cls()
inst.ia = ia
inst.host = host
inst.path = path
inst.ext_hdrs = ext_hdrs
inst.port = port
return inst
def get_addr(self):
return SCIONAddr.from_values(self.ia, self.host)
def close(self): # Close communication between peers.
pass
class UDPMetadata(MetadataBase):
"""
Class for UDP message metadata
"""
pass
class SCMPMetadata(MetadataBase):
"""
Class for SCMP message metadata
"""
pass
class TCPMetadata(MetadataBase):
"""
Class for TCP message metadata
"""
@classmethod
def from_values(cls, ia=None, host=None, path=None,
ext_hdrs=(), port=0, sock=None, flags=0):
inst = super().from_values(ia, host, path, ext_hdrs, port)
inst.sock = sock
inst.flags = flags
return inst
def close(self):
self.sock.active = False
class RawMetadata(MetadataBase):
# FIXME(PSz): needed only by python router.
def __init__(self):
self.packet = None
self.addr = None
self.from_local_as = None
@classmethod
def from_values(cls, packet, addr, from_local_as):
inst = RawMetadata()
inst.packet = packet
inst.addr = addr
inst.from_local_as = from_local_as
return inst
class SockOnlyMetadata(MetadataBase):
def __init__(self):
self.sock = None
@classmethod
def from_values(cls, sock):
inst = SockOnlyMetadata()
inst.sock = sock
return inst