quaff 0.4.2 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (4) hide show
  1. data/lib/call.rb +6 -0
  2. data/lib/endpoint.rb +8 -4
  3. data/lib/sources.rb +29 -21
  4. metadata +1 -1
@@ -27,6 +27,7 @@ class Call
27
27
 
28
28
  def initialize(cxn,
29
29
  cid,
30
+ instance_id=nil,
30
31
  uri="sip:5557777888@#{Utils::local_ip}",
31
32
  destination=nil,
32
33
  target_uri=nil)
@@ -42,6 +43,7 @@ class Call
42
43
  setdest(destination, recv_from_this: true) if destination
43
44
  set_callee target_uri if target_uri
44
45
  @routeset = []
46
+ @instance_id = instance_id
45
47
  end
46
48
 
47
49
  def change_cid cid
@@ -194,6 +196,10 @@ class Call
194
196
  "Contact" => "<sip:quaff@#{Utils::local_ip}:#{@cxn.local_port};transport=#{@cxn.transport};ob>",
195
197
  }
196
198
 
199
+ if @instance_id
200
+ defaults["Contact"] += ";+sip.instance=\"<urn:uuid:"+@instance_id+">\""
201
+ end
202
+
197
203
  is_request = code.nil?
198
204
  if is_request
199
205
  defaults['Route'] = @routeset
@@ -10,7 +10,8 @@ require_relative './sources.rb'
10
10
 
11
11
  module Quaff
12
12
  class BaseEndpoint
13
- attr_accessor :msg_trace, :uri, :sdp_port, :sdp_socket
13
+ attr_accessor :msg_trace, :uri, :sdp_port, :sdp_socket, :instance_id
14
+ attr_reader :msg_log
14
15
 
15
16
  def setup_sdp
16
17
  @sdp_socket = UDPSocket.new
@@ -31,13 +32,13 @@ module Quaff
31
32
  def incoming_call *args
32
33
  call_id ||= get_new_call_id
33
34
  puts "Call-Id for endpoint on #{@lport} is #{call_id}" if @msg_trace
34
- Call.new(self, call_id, *args)
35
+ Call.new(self, call_id, @instance_id, *args)
35
36
  end
36
37
 
37
38
  def outgoing_call to_uri
38
39
  call_id = generate_call_id
39
40
  puts "Call-Id for endpoint on #{@lport} is #{call_id}" if @msg_trace
40
- Call.new(self, call_id, @uri, @outbound_connection, to_uri)
41
+ Call.new(self, call_id, @instance_id, @uri, @outbound_connection, to_uri)
41
42
  end
42
43
 
43
44
  def create_client(uri, username, password, outbound_proxy, outbound_port=5060)
@@ -51,6 +52,7 @@ module Quaff
51
52
  end
52
53
 
53
54
  def initialize(uri, username, password, local_port, outbound_proxy=nil, outbound_port=5060)
55
+ @msg_log = Array.new
54
56
  @uri = uri
55
57
  @resolver = Resolv::DNS.new
56
58
  @username = username
@@ -88,7 +90,8 @@ module Quaff
88
90
  end
89
91
 
90
92
  def send_msg(data, source)
91
- puts "Endpoint on #{@lport} sending #{data} to #{source.inspect}" if @msg_trace
93
+ @msg_log.push "Endpoint on #{@lport} sending:\n\n#{data.strip}\n\nto #{source.inspect}"
94
+ puts "Endpoint on #{@lport} sending #{data} to #{source.inspect}" if @msg_trace
92
95
  source.send_msg(@cxn, data)
93
96
  end
94
97
 
@@ -139,6 +142,7 @@ module Quaff
139
142
  end
140
143
 
141
144
  def queue_msg(msg, source)
145
+ @msg_log.push "Endpoint on #{@lport} received:\n\n#{msg.to_s.strip}\n\nfrom #{source.inspect}"
142
146
  puts "Endpoint on #{@lport} received #{msg} from
143
147
  ##{source.inspect}" if @msg_trace
144
148
  msg.source = source
@@ -1,12 +1,12 @@
1
1
  require 'socket'
2
2
  module Quaff
3
- class Source
3
+ class Source
4
4
  def remote_ip
5
- @ip
5
+ @ip
6
6
  end
7
7
 
8
8
  def remote_port
9
- @port
9
+ @port
10
10
  end
11
11
 
12
12
  def close cxn
@@ -15,47 +15,55 @@ class Source
15
15
  def sock
16
16
  nil
17
17
  end
18
- end
19
18
 
20
- class UDPSource < Source
19
+ def to_s
20
+ "#{@ip}:#{@port} (#{@transport})"
21
+ end
22
+ end
23
+
24
+ class UDPSource < Source
21
25
  def initialize ip, port
22
- @ip, @port = ip, port
26
+ @transport = "UDP"
27
+ @ip, @port = ip, port
23
28
  end
24
29
 
25
30
  def send_msg cxn, data
26
- cxn.send(data, 0, @ip, @port)
31
+ cxn.send(data, 0, @ip, @port)
27
32
  end
28
- end
33
+ end
29
34
 
30
- class UDPSourceFromAddrinfo < UDPSource
35
+ class UDPSourceFromAddrinfo < UDPSource
31
36
  def initialize addrinfo
32
- @ip, @port = addrinfo[3], addrinfo[1]
37
+ @transport = "UDP"
38
+ @ip, @port = addrinfo[3], addrinfo[1]
33
39
  end
34
- end
40
+ end
35
41
 
36
42
 
37
- class TCPSource < Source
38
- attr_reader :sock
43
+ class TCPSource < Source
44
+ attr_reader :sock
39
45
 
40
46
  def initialize ip, port
41
- @sock = TCPSocket.new ip, port
42
- @port, @ip = port, ip
47
+ @transport = "TCP"
48
+ @sock = TCPSocket.new ip, port
49
+ @port, @ip = port, ip
43
50
  end
44
51
 
45
52
  def send_msg _, data
46
- @sock.sendmsg data
53
+ @sock.sendmsg data
47
54
  end
48
55
 
49
56
  def close cxn
50
- @sock.close
51
- cxn.sockets.delete(@sock)
57
+ @sock.close
58
+ cxn.sockets.delete(@sock)
52
59
  end
53
- end
60
+ end
54
61
 
55
- class TCPSourceFromSocket < TCPSource
62
+ class TCPSourceFromSocket < TCPSource
56
63
  def initialize sock
64
+ @transport = "TCP"
57
65
  @sock = sock
58
66
  @port, @ip = Socket.unpack_sockaddr_in(@sock.getpeername)
59
67
  end
60
- end
68
+ end
61
69
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: quaff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: