Пример #1
0
        /// <summary>
        /// Call this method to accept the incoming stream.
        /// </summary>
        /// <param name="DataCallback">Method called when data has been received.</param>
        /// <param name="CloseCallback">Method called when stream has been closed.</param>
        /// <param name="State">State object to pass on to the callback method.</param>
        /// <returns>If the stream acceptance was completed (true), or if somebody else accepted the stream beforehand (false).</returns>
        public bool AcceptStream(DataReceivedEventHandler DataCallback, StreamEventHandler CloseCallback, object State)
        {
            if (this.dataCallback is null)
            {
                this.dataCallback  = DataCallback;
                this.closeCallback = CloseCallback;
                this.state         = State;

                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
            internal void StateChanged(object Sender, EventArgs e)
            {
                switch (this.stream.State)
                {
                case Socks5State.Authenticated:
                    this.stream.CONNECT(this.streamId, this.proxy.client.FullJID, this.destinationJid);
                    break;

                case Socks5State.Connected:
                    StringBuilder Xml = new StringBuilder();

                    Xml.Append("<query xmlns=\"");
                    Xml.Append(Namespace);
                    Xml.Append("\" sid=\"");
                    Xml.Append(this.streamId);
                    Xml.Append("\"><activate>");
                    Xml.Append(this.destinationJid);
                    Xml.Append("</activate></query>");

                    if (this.proxy.e2e != null)
                    {
                        this.proxy.e2e.SendIqSet(this.proxy.client, E2ETransmission.NormalIfNotE2E, this.proxy.jid, Xml.ToString(),
                                                 this.proxy.ActivationResponse, this);
                    }
                    else
                    {
                        this.proxy.client.SendIqSet(this.proxy.jid, Xml.ToString(), this.proxy.ActivationResponse, this);
                    }
                    break;

                case Socks5State.Error:
                case Socks5State.Offline:
                    if (this.stream != null)
                    {
                        this.stream.Dispose();
                    }
                    this.proxy.Callback(this.callback, this.state, false, null, this.streamId);
                    this.callback = null;
                    break;
                }
            }
Пример #3
0
        private async Task Callback(StreamEventHandler Callback, object State, bool Ok, Socks5Client Stream, string StreamId)
        {
            if (!Ok && !string.IsNullOrEmpty(StreamId))
            {
                lock (this.streams)
                {
                    this.streams.Remove(StreamId);
                }
            }

            if (Callback != null)
            {
                try
                {
                    await Callback(this, new StreamEventArgs(Ok, Stream, State));
                }
                catch (Exception ex)
                {
                    Log.Critical(ex);
                }
            }
        }
Пример #4
0
        /// <summary>
        /// Initiates a mediated SOCKS5 session with another.
        /// </summary>
        /// <param name="DestinationJid">JID of destination.</param>
        /// <param name="StreamId">Stream ID to use.</param>
        /// <param name="Callback">Method to call when initiation attempt completes.</param>
        /// <param name="State">State object to pass on to callback method.</param>
        public async Task InitiateSession(string DestinationJid, string StreamId, StreamEventHandler Callback, object State)
        {
            if (!this.hasProxy)
            {
                await this.Callback(Callback, State, false, null, null);

                return;
            }

            lock (this.streams)
            {
                if (string.IsNullOrEmpty(StreamId))
                {
                    do
                    {
                        StreamId = Guid.NewGuid().ToString().Replace("-", string.Empty);
                    }while (this.streams.ContainsKey(StreamId));
                }
                else if (this.streams.ContainsKey(StreamId))
                {
                    StreamId = null;
                }

                if (StreamId != null)
                {
                    this.streams[StreamId] = null;
                }
            }

            if (StreamId is null)
            {
                await this.Callback(Callback, State, false, null, null);

                return;
            }

            StringBuilder Xml = new StringBuilder();

            Xml.Append("<query xmlns=\"");
            Xml.Append(Namespace);
            Xml.Append("\" sid=\"");
            Xml.Append(StreamId);
            Xml.Append("\"><streamhost host=\"");
            Xml.Append(this.host);
            Xml.Append("\" jid=\"");
            Xml.Append(this.jid);
            Xml.Append("\" port=\"");
            Xml.Append(this.port.ToString());
            Xml.Append("\"/></query>");

            InitiationRec Rec = new InitiationRec()
            {
                destinationJid = DestinationJid,
                streamId       = StreamId,
                callback       = Callback,
                state          = State,
                proxy          = this
            };

            if (this.e2e != null)
            {
                this.e2e.SendIqSet(this.client, E2ETransmission.NormalIfNotE2E, DestinationJid, Xml.ToString(), this.InitiationResponse, Rec);
            }
            else
            {
                this.client.SendIqSet(DestinationJid, Xml.ToString(), this.InitiationResponse, Rec);
            }
        }
Пример #5
0
 /// <summary>
 /// Initiates a mediated SOCKS5 session with another.
 /// </summary>
 /// <param name="DestinationJid">JID of destination.</param>
 /// <param name="Callback">Method to call when initiation attempt completes.</param>
 /// <param name="State">State object to pass on to callback method.</param>
 public Task InitiateSession(string DestinationJid, StreamEventHandler Callback, object State)
 {
     return(this.InitiateSession(DestinationJid, null, Callback, State));
 }
Пример #6
0
 /// <summary>
 /// Initiates a mediated SOCKS5 session with another.
 /// </summary>
 /// <param name="DestinationJid">JID of destination.</param>
 /// <param name="Callback">Method to call when initiation attempt completes.</param>
 /// <param name="State">State object to pass on to callback method.</param>
 public void InitiateSession(string DestinationJid, StreamEventHandler Callback, object State)
 {
     this.InitiateSession(DestinationJid, null, Callback, State);
 }
Пример #7
0
 // DI constructor
 public RtBot(StreamEventHandler eventHandler)
 {
     _eventHandler = eventHandler;
 }