Class: Blather::FileTransfer::S5b

Inherits:
Object
  • Object
show all
Defined in:
lib/blather/file_transfer/s5b.rb

Overview

SOCKS5 Bytestreams Transfer helper Takes care of accepting, declining and offering file transfers through the stream

Defined Under Namespace

Classes: SocketConnection

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(stream, iq) ⇒ S5b

Returns a new instance of S5b.



16
17
18
19
20
21
# File 'lib/blather/file_transfer/s5b.rb', line 16

def initialize(stream, iq)
  @stream = stream
  @iq = iq
  @allow_ibb_fallback = true
  @allow_private_ips = false
end

Instance Attribute Details

#allow_ibb_fallbackObject

Set this to false if you don’t want to fallback to In-Band Bytestreams



8
9
10
# File 'lib/blather/file_transfer/s5b.rb', line 8

def allow_ibb_fallback
  @allow_ibb_fallback
end

#allow_private_ipsObject

Set this to true if the buddies of your bot will be in the same local network

Usually IM clients advertise all network addresses which they can determine. Skipping the local ones can save time if your bot is not in the same local network as it’s buddies



14
15
16
# File 'lib/blather/file_transfer/s5b.rb', line 14

def allow_private_ips
  @allow_private_ips
end

Instance Method Details

#accept(handler, *params) ⇒ Object

Accept an incoming file-transfer

Parameters:

  • handler (module)

    the handler for incoming data, see Blather::FileTransfer::SimpleFileReceiver for an example

  • params (Array)

    the params to be passed into the handler



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/blather/file_transfer/s5b.rb', line 27

def accept(handler, *params)
  @streamhosts = @iq.streamhosts
  @streamhosts.delete_if {|s| begin IPAddr.new(s.host).private? rescue false end } unless @allow_private_ips
  @socket_address = Digest::SHA1.hexdigest("#{@iq.sid}#{@iq.from}#{@iq.to}")

  @handler = handler
  @params = params

  connect_next_streamhost
  @stream.clear_handlers :s5b_open, :from => @iq.from
end

#declineObject

Decline an incoming file-transfer



40
41
42
43
# File 'lib/blather/file_transfer/s5b.rb', line 40

def decline
  @stream.clear_handlers :s5b_open, :from => @iq.from
  @stream.write StanzaError.new(@iq, 'not-acceptable', :auth).to_node
end

#offerObject

Offer a file to somebody, not implemented yet



46
47
48
# File 'lib/blather/file_transfer/s5b.rb', line 46

def offer
  # TODO: implement
end