Class: Quaff::BaseEndpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/endpoint.rb

Direct Known Subclasses

TCPSIPEndpoint, UDPSIPEndpoint

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, username, password, local_port, outbound_proxy = nil, outbound_port = 5060) ⇒ BaseEndpoint

Returns a new instance of BaseEndpoint.



53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/endpoint.rb', line 53

def initialize(uri, username, password, local_port, outbound_proxy=nil, outbound_port=5060)
  @uri = uri
  @resolver = Resolv::DNS.new
  @username = username
  @password = password
  @lport = local_port
  initialize_connection
  if outbound_proxy
    @outbound_connection = new_connection(outbound_proxy, outbound_port)
  end
  initialize_queues
  start
end

Instance Attribute Details

#msg_traceObject

Returns the value of attribute msg_trace.



13
14
15
# File 'lib/endpoint.rb', line 13

def msg_trace
  @msg_trace
end

#sdp_portObject

Returns the value of attribute sdp_port.



13
14
15
# File 'lib/endpoint.rb', line 13

def sdp_port
  @sdp_port
end

#sdp_socketObject

Returns the value of attribute sdp_socket.



13
14
15
# File 'lib/endpoint.rb', line 13

def sdp_socket
  @sdp_socket
end

#uriObject

Returns the value of attribute uri.



13
14
15
# File 'lib/endpoint.rb', line 13

def uri
  @uri
end

Instance Method Details

#add_call_id(cid) ⇒ Object



71
72
73
# File 'lib/endpoint.rb', line 71

def add_call_id cid
    @messages[cid] ||= Queue.new
end

#add_sock(sock) ⇒ Object



28
29
# File 'lib/endpoint.rb', line 28

def add_sock sock
end

#create_aka_client(uri, username, key, op, outbound_proxy, outbound_port = 5060) ⇒ Object



50
51
# File 'lib/endpoint.rb', line 50

def create_aka_client(uri, username, key, op, outbound_proxy, outbound_port=5060)
end

#create_client(uri, username, password, outbound_proxy, outbound_port = 5060) ⇒ Object



43
44
# File 'lib/endpoint.rb', line 43

def create_client(uri, username, password, outbound_proxy, outbound_port=5060)
end

#create_server(uri, local_port = 5060, outbound_proxy = nil, outbound_port = 5060) ⇒ Object



46
47
48
# File 'lib/endpoint.rb', line 46

def create_server(uri, local_port=5060, outbound_proxy=nil, outbound_port=5060)

end

#generate_call_idObject



21
22
23
# File 'lib/endpoint.rb', line 21

def generate_call_id
  digest = Digest::MD5.hexdigest(rand(60000).to_s)
end

#get_new_call_id(time_limit = 30) ⇒ Object



75
76
77
# File 'lib/endpoint.rb', line 75

def get_new_call_id time_limit=30
    Timeout::timeout(time_limit) { @call_ids.deq }
end

#get_new_message(cid, time_limit = 30) ⇒ Object



79
80
81
# File 'lib/endpoint.rb', line 79

def get_new_message(cid, time_limit=30)
  Timeout::timeout(time_limit) { @messages[cid].deq }
end

#incoming_call(*args) ⇒ Object



31
32
33
34
35
# File 'lib/endpoint.rb', line 31

def incoming_call *args
  call_id ||= get_new_call_id
  puts "Call-Id for endpoint on #{@lport} is #{call_id}" if @msg_trace
  Call.new(self, call_id, *args)
end

#local_portObject



67
68
69
# File 'lib/endpoint.rb', line 67

def local_port
    @lport
end

#mark_call_dead(cid) ⇒ Object



83
84
85
86
87
88
# File 'lib/endpoint.rb', line 83

def mark_call_dead(cid)
    @messages.delete cid
    now = Time.now
    @dead_calls[cid] = now + 30
    @dead_calls = @dead_calls.keep_if {|k, v| v > now}
end

#outgoing_call(to_uri) ⇒ Object



37
38
39
40
41
# File 'lib/endpoint.rb', line 37

def outgoing_call to_uri
  call_id = generate_call_id
  puts "Call-Id for endpoint on #{@lport} is #{call_id}" if @msg_trace
  Call.new(self, call_id, @uri, @outbound_connection, to_uri)
end

#register(expires = "3600", aka = false) ⇒ Object



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/endpoint.rb', line 100

def register expires="3600", aka=false
  @reg_call ||= outgoing_call(@uri)
  auth_hdr = Quaff::Auth.gen_empty_auth_header @username
  @reg_call.update_branch
  @reg_call.send_request("REGISTER", "", {"Authorization" =>  auth_hdr, "Expires" => expires.to_s})
  response_data = @reg_call.recv_response("401|200")
  if response_data.status_code == "401"
    if aka
      rand = Quaff::Auth.extract_rand response_data.header("WWW-Authenticate")
      password = @kernel.f3 rand
    else
      password = @password
    end
    auth_hdr = Quaff::Auth.gen_auth_header response_data.header("WWW-Authenticate"), @username, @password, "REGISTER", @uri
    @reg_call.update_branch
    @reg_call.send_request("REGISTER", "", {"Authorization" =>  auth_hdr, "Expires" => expires.to_s})
    response_data = @reg_call.recv_response("200")
  end
  return response_data # always the 200 OK
end

#send_msg(data, source) ⇒ Object



90
91
92
93
# File 'lib/endpoint.rb', line 90

def send_msg(data, source)
    puts "Endpoint on #{@lport} sending #{data} to #{source.inspect}" if @msg_trace
    source.send_msg(@cxn, data)
end

#set_aka_credentials(key, op) ⇒ Object



95
96
97
98
# File 'lib/endpoint.rb', line 95

def set_aka_credentials key, op
  @kernel = Milenage.Kernel key
  @kernel.op = op
end

#setup_sdpObject



15
16
17
18
19
# File 'lib/endpoint.rb', line 15

def setup_sdp
  @sdp_socket = UDPSocket.new
  @sdp_socket.bind('0.0.0.0', 0)
  @sdp_port = @sdp_socket.addr[1]
end

#terminateObject



25
26
# File 'lib/endpoint.rb', line 25

def terminate
end

#unregisterObject



121
122
123
# File 'lib/endpoint.rb', line 121

def unregister
  register 0
end