Class: Quaff::BaseEndpoint
- Inherits:
-
Object
- Object
- Quaff::BaseEndpoint
- Defined in:
- lib/endpoint.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#instance_id ⇒ Object
Returns the value of attribute instance_id.
-
#msg_log ⇒ Object
readonly
Returns the value of attribute msg_log.
-
#msg_trace ⇒ Object
Returns the value of attribute msg_trace.
-
#sdp_port ⇒ Object
Returns the value of attribute sdp_port.
-
#sdp_socket ⇒ Object
Returns the value of attribute sdp_socket.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #add_call_id(cid) ⇒ Object
- #add_sock(sock) ⇒ Object
- #create_aka_client(uri, username, key, op, outbound_proxy, outbound_port = 5060) ⇒ Object
- #create_client(uri, username, password, outbound_proxy, outbound_port = 5060) ⇒ Object
- #create_server(uri, local_port = 5060, outbound_proxy = nil, outbound_port = 5060) ⇒ Object
- #generate_call_id ⇒ Object
- #get_new_call_id(time_limit = 30) ⇒ Object
- #get_new_message(cid, time_limit = 30) ⇒ Object
- #incoming_call(*args) ⇒ Object
-
#initialize(uri, username, password, local_port, outbound_proxy = nil, outbound_port = 5060) ⇒ BaseEndpoint
constructor
A new instance of BaseEndpoint.
- #local_port ⇒ Object
- #mark_call_dead(cid) ⇒ Object
- #outgoing_call(to_uri) ⇒ Object
- #register(expires = "3600", aka = false) ⇒ Object
- #send_msg(data, source) ⇒ Object
- #set_aka_credentials(key, op) ⇒ Object
- #setup_sdp ⇒ Object
- #terminate ⇒ Object
- #unregister ⇒ Object
Constructor Details
#initialize(uri, username, password, local_port, outbound_proxy = nil, outbound_port = 5060) ⇒ BaseEndpoint
Returns a new instance of BaseEndpoint.
54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/endpoint.rb', line 54 def initialize(uri, username, password, local_port, outbound_proxy=nil, outbound_port=5060) @msg_log = Array.new @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
#instance_id ⇒ Object
Returns the value of attribute instance_id.
13 14 15 |
# File 'lib/endpoint.rb', line 13 def instance_id @instance_id end |
#msg_log ⇒ Object (readonly)
Returns the value of attribute msg_log.
14 15 16 |
# File 'lib/endpoint.rb', line 14 def msg_log @msg_log end |
#msg_trace ⇒ Object
Returns the value of attribute msg_trace.
13 14 15 |
# File 'lib/endpoint.rb', line 13 def msg_trace @msg_trace end |
#sdp_port ⇒ Object
Returns the value of attribute sdp_port.
13 14 15 |
# File 'lib/endpoint.rb', line 13 def sdp_port @sdp_port end |
#sdp_socket ⇒ Object
Returns the value of attribute sdp_socket.
13 14 15 |
# File 'lib/endpoint.rb', line 13 def sdp_socket @sdp_socket end |
#uri ⇒ Object
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
73 74 75 |
# File 'lib/endpoint.rb', line 73 def add_call_id cid @messages[cid] ||= Queue.new end |
#add_sock(sock) ⇒ Object
29 30 |
# File 'lib/endpoint.rb', line 29 def add_sock sock end |
#create_aka_client(uri, username, key, op, outbound_proxy, outbound_port = 5060) ⇒ Object
51 52 |
# File 'lib/endpoint.rb', line 51 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
44 45 |
# File 'lib/endpoint.rb', line 44 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
47 48 49 |
# File 'lib/endpoint.rb', line 47 def create_server(uri, local_port=5060, outbound_proxy=nil, outbound_port=5060) end |
#generate_call_id ⇒ Object
22 23 24 |
# File 'lib/endpoint.rb', line 22 def generate_call_id digest = Digest::MD5.hexdigest(rand(60000).to_s) end |
#get_new_call_id(time_limit = 30) ⇒ Object
77 78 79 |
# File 'lib/endpoint.rb', line 77 def get_new_call_id time_limit=30 Timeout::timeout(time_limit) { @call_ids.deq } end |
#get_new_message(cid, time_limit = 30) ⇒ Object
81 82 83 |
# File 'lib/endpoint.rb', line 81 def (cid, time_limit=30) Timeout::timeout(time_limit) { @messages[cid].deq } end |
#incoming_call(*args) ⇒ Object
32 33 34 35 36 |
# File 'lib/endpoint.rb', line 32 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, @instance_id, *args) end |
#local_port ⇒ Object
69 70 71 |
# File 'lib/endpoint.rb', line 69 def local_port @lport end |
#mark_call_dead(cid) ⇒ Object
85 86 87 88 89 90 |
# File 'lib/endpoint.rb', line 85 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
38 39 40 41 42 |
# File 'lib/endpoint.rb', line 38 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, @instance_id, @uri, @outbound_connection, to_uri) end |
#register(expires = "3600", aka = false) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/endpoint.rb', line 103 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
92 93 94 95 96 |
# File 'lib/endpoint.rb', line 92 def send_msg(data, source) @msg_log.push "Endpoint on #{@lport} sending:\n\n#{data.strip}\n\nto #{source.inspect}" puts "Endpoint on #{@lport} sending #{data} to #{source.inspect}" if @msg_trace source.send_msg(@cxn, data) end |
#set_aka_credentials(key, op) ⇒ Object
98 99 100 101 |
# File 'lib/endpoint.rb', line 98 def set_aka_credentials key, op @kernel = Milenage.Kernel key @kernel.op = op end |
#setup_sdp ⇒ Object
16 17 18 19 20 |
# File 'lib/endpoint.rb', line 16 def setup_sdp @sdp_socket = UDPSocket.new @sdp_socket.bind('0.0.0.0', 0) @sdp_port = @sdp_socket.addr[1] end |
#terminate ⇒ Object
26 27 |
# File 'lib/endpoint.rb', line 26 def terminate end |
#unregister ⇒ Object
124 125 126 |
# File 'lib/endpoint.rb', line 124 def unregister register 0 end |