From 642dac9aa0b90dd2f17df5dddd0e7914a7d306d3 Mon Sep 17 00:00:00 2001 From: hrxi Date: Sat, 20 Jul 2019 23:14:40 +0200 Subject: Add support for Jingle SOCKS5 bytestreams (XEP-0260) --- .../xep/0261_jingle_in_band_bytestreams.vala | 35 +++++++++++++++------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala') diff --git a/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala b/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala index dc2e8d7c..1a810ee8 100644 --- a/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala +++ b/xmpp-vala/src/module/xep/0261_jingle_in_band_bytestreams.vala @@ -30,28 +30,38 @@ public class Module : Jingle.Transport, XmppStreamModule { public Jingle.TransportType transport_type() { return Jingle.TransportType.STREAMING; } - public Jingle.TransportParameters create_transport_parameters() { - return new Parameters(random_uuid(), DEFAULT_BLOCKSIZE); + public int transport_priority() { + return 0; } - public Jingle.TransportParameters parse_transport_parameters(StanzaNode transport) throws Jingle.IqError { - return Parameters.parse(transport); + public Jingle.TransportParameters create_transport_parameters(XmppStream stream, Jid local_full_jid, Jid peer_full_jid) { + return new Parameters.create(peer_full_jid, random_uuid()); + } + public Jingle.TransportParameters parse_transport_parameters(XmppStream stream, Jid local_full_jid, Jid peer_full_jid, StanzaNode transport) throws Jingle.IqError { + return Parameters.parse(peer_full_jid, transport); } } class Parameters : Jingle.TransportParameters, Object { + public Jingle.Role role { get; private set; } + public Jid peer_full_jid { get; private set; } public string sid { get; private set; } public int block_size { get; private set; } - public Parameters(string sid, int block_size) { + private Parameters(Jingle.Role role, Jid peer_full_jid, string sid, int block_size) { + this.role = role; + this.peer_full_jid = peer_full_jid; this.sid = sid; this.block_size = block_size; } - public static Parameters parse(StanzaNode transport) throws Jingle.IqError { + public Parameters.create(Jid peer_full_jid, string sid) { + this(Jingle.Role.INITIATOR, peer_full_jid, sid, DEFAULT_BLOCKSIZE); + } + public static Parameters parse(Jid peer_full_jid, StanzaNode transport) throws Jingle.IqError { string? sid = transport.get_attribute("sid"); int block_size = transport.get_attribute_int("block-size"); if (sid == null || block_size <= 0 || block_size > MAX_BLOCKSIZE) { throw new Jingle.IqError.BAD_REQUEST("missing or invalid sid or blocksize"); } - return new Parameters(sid, block_size); + return new Parameters(Jingle.Role.RESPONDER, peer_full_jid, sid, block_size); } public string transport_ns_uri() { return NS_URI; @@ -62,15 +72,18 @@ class Parameters : Jingle.TransportParameters, Object { .put_attribute("block-size", block_size.to_string()) .put_attribute("sid", sid); } - public void update_transport(StanzaNode transport) throws Jingle.IqError { - Parameters other = Parameters.parse(transport); + public void on_transport_accept(StanzaNode transport) throws Jingle.IqError { + Parameters other = Parameters.parse(peer_full_jid, transport); if (other.sid != sid || other.block_size > block_size) { throw new Jingle.IqError.NOT_ACCEPTABLE("invalid IBB sid or block_size"); } block_size = other.block_size; } - public IOStream create_transport_connection(XmppStream stream, Jid peer_full_jid, Jingle.Role role) { - return InBandBytestreams.Connection.create(stream, peer_full_jid, sid, block_size, role == Jingle.Role.INITIATOR); + public void on_transport_info(StanzaNode transport) throws Jingle.IqError { + throw new Jingle.IqError.UNSUPPORTED_INFO("transport-info not supported for IBBs"); + } + public void create_transport_connection(XmppStream stream, Jingle.Session session) { + session.set_transport_connection(stream, InBandBytestreams.Connection.create(stream, peer_full_jid, sid, block_size, role == Jingle.Role.INITIATOR)); } } -- cgit v1.2.3-54-g00ecf