1
2
3
4
5
6
7
8
9
10
11
12
13
14 """
15 Handles Jingle Transports (currently only ICE-UDP)
16 """
17
18 import xmpp
19
20 transports = {}
21
26
27
29 """
30 Possible types of a JingleTransport
31 """
32 datagram = 1
33 streaming = 2
34
35
37 """
38 An abstraction of a transport in Jingle sessions
39 """
40
42 self.type = type_
43 self.candidates = []
44 self.remote_candidates = []
45
47 for candidate in self.candidates:
48 yield self.make_candidate(candidate)
49
51 """
52 Build a candidate stanza for the given candidate
53 """
54 pass
55
57 """
58 Build a transport stanza with the given candidates (or self.candidates if
59 candidates is None)
60 """
61 if not candidates:
62 candidates = self._iter_candidates()
63 else:
64 candidates = (self.make_candidate(candidate) for candidate in candidates)
65 transport = xmpp.Node('transport', payload=candidates)
66 return transport
67
69 """
70 Return the list of transport candidates from a transport stanza
71 """
72 return []
73
74
75 import farsight
76
80
82 types = {farsight.CANDIDATE_TYPE_HOST: 'host',
83 farsight.CANDIDATE_TYPE_SRFLX: 'srflx',
84 farsight.CANDIDATE_TYPE_PRFLX: 'prflx',
85 farsight.CANDIDATE_TYPE_RELAY: 'relay',
86 farsight.CANDIDATE_TYPE_MULTICAST: 'multicast'}
87 attrs = {
88 'component': candidate.component_id,
89 'foundation': '1',
90 'generation': '0',
91 'ip': candidate.ip,
92 'network': '0',
93 'port': candidate.port,
94 'priority': int(candidate.priority),
95 }
96 if candidate.type in types:
97 attrs['type'] = types[candidate.type]
98 if candidate.proto == farsight.NETWORK_PROTOCOL_UDP:
99 attrs['protocol'] = 'udp'
100 else:
101
102 attrs['protocol'] = 'tcp'
103 return xmpp.Node('candidate', attrs=attrs)
104
113
115 candidates = []
116 for candidate in transport.iterTags('candidate'):
117 cand = farsight.Candidate()
118 cand.component_id = int(candidate['component'])
119 cand.ip = str(candidate['ip'])
120 cand.port = int(candidate['port'])
121 cand.foundation = str(candidate['foundation'])
122
123 cand.priority = int(candidate['priority'])
124
125 if candidate['protocol'] == 'udp':
126 cand.proto = farsight.NETWORK_PROTOCOL_UDP
127 else:
128
129 cand.proto = farsight.NETWORK_PROTOCOL_TCP
130
131 cand.username = str(transport['ufrag'])
132 cand.password = str(transport['pwd'])
133
134
135 types = {'host': farsight.CANDIDATE_TYPE_HOST,
136 'srflx': farsight.CANDIDATE_TYPE_SRFLX,
137 'prflx': farsight.CANDIDATE_TYPE_PRFLX,
138 'relay': farsight.CANDIDATE_TYPE_RELAY,
139 'multicast': farsight.CANDIDATE_TYPE_MULTICAST}
140 if 'type' in candidate and candidate['type'] in types:
141 cand.type = types[candidate['type']]
142 else:
143 print 'Unknown type %s', candidate['type']
144 candidates.append(cand)
145 self.remote_candidates.extend(candidates)
146 return candidates
147
148 transports[xmpp.NS_JINGLE_ICE_UDP] = JingleTransportICEUDP
149