module PryRemoteEm::Proto
Constants
- PREAMBLE
- PREAMBLE_LEN
- SEPERATOR
- SEPERATOR_LEN
Public Instance Methods
receive_auth(a, b = nil)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 99 def receive_auth(a, b = nil); end
receive_completion(c)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 104 def receive_completion(c); end
receive_data(d)
click to toggle source
Each frame is a string consisting of 4 parts
1. preamble (PRYEM) 2. length in characters of crc, a seperator, and body 3. CRC 4. JSON encoded body
It is possible and likely that #receive_data will be given more than one frame at a time, or an incomplete frame. @example “PRYEM42 3900082256 {"g":"PryRemoteEm 0.7.0 pryem"}PRYEM22 1794245389 {"a":false}”
# File lib/pry-remote-em/proto.rb, line 29 def receive_data(d) return unless d && d.bytesize > 0 @buffer ||= "" # inlieu of a post_init @buffer << d while @buffer && !@buffer.empty? return unless @buffer.bytesize >= PREAMBLE_LEN && (len_ends = @buffer.index(SEPERATOR)) && (crc_ends = @buffer.index(SEPERATOR, len_ends)) if (preamble = @buffer[0...PREAMBLE_LEN]) != PREAMBLE raise "message is not in proper format; expected #{PREAMBLE.inspect} not #{preamble.inspect}" end length = @buffer[PREAMBLE_LEN ... len_ends].to_i return if len_ends + length > @buffer.bytesize crc_start = len_ends + SEPERATOR_LEN crc, data = @buffer[crc_start ... crc_start + length].split(SEPERATOR, 2) crc = crc.to_i @buffer = @buffer[crc_start + length .. -1] if (dcrc = Zlib::crc32(data)) == crc receive_json(JSON.load(data)) else warn("data crc #{dcrc} doesn't match crc #{crc.inspect}; discarding #{data.inspect}") end end @buffer end
receive_json(j)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 55 def receive_json(j) if j['p'] receive_prompt(j['p']) elsif j['d'] receive_raw(j['d']) elsif j['m'] receive_msg(j['m']) elsif j['mb'] receive_msg_bcast(j['mb']) elsif j['s'] receive_shell_cmd(j['s']) elsif j.include?('sc') receive_shell_result(j['sc']) elsif j['g'] receive_banner(*j['g'].split(" ", 3)) elsif j['c'] receive_completion(j['c']) elsif j.include?('a') receive_auth(*Array(j['a'])) elsif j['sd'] receive_shell_data(j['sd']) elsif j['ssc'] receive_shell_sig(:term) elsif j['hb'] receive_heartbeat(j['hb']) elsif j['rs'] receive_register_server(*Array(j['rs'])) elsif j['urs'] receive_unregister_server(j['urs']) elsif j.include?('sl') j['sl'] ? receive_server_list(j['sl']) : receive_server_list elsif j['tls'] receive_start_tls elsif j['pc'] receive_proxy_connection(j['pc']) else receive_unknown(j) end j end
receive_msg(m)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 100 def receive_msg(m); end
receive_msg_bcast(mb)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 101 def receive_msg_bcast(mb); end
receive_prompt(p)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 97 def receive_prompt(p); end
receive_proxy_connection(url)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 116 def receive_proxy_connection(url); end
receive_raw(r)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 105 def receive_raw(r); end
receive_register_server(url, name)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 112 def receive_register_server(url, name); end
receive_server_list(list = nil)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 114 def receive_server_list(list = nil); end
receive_shell_cmd(c)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 102 def receive_shell_cmd(c); end
receive_shell_data(d)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 107 def receive_shell_data(d); end
receive_shell_result(c)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 103 def receive_shell_result(c); end
receive_shell_sig(sym)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 106 def receive_shell_sig(sym); end
receive_start_tls()
click to toggle source
# File lib/pry-remote-em/proto.rb, line 110 def receive_start_tls; end
receive_unknown(j)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 108 def receive_unknown(j); end
receive_unregister_server(url)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 113 def receive_unregister_server(url); end
send_auth(a)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 121 def send_auth(a) send_json({:a => a}) end
send_completion(word)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 139 def send_completion(word) send_json({:c => word}) end
send_data(data)
click to toggle source
Calls superclass method
# File lib/pry-remote-em/proto.rb, line 15 def send_data(data) crc = Zlib::crc32(data).to_s msg = PREAMBLE + (data.bytesize + crc.bytesize + SEPERATOR_LEN).to_s + SEPERATOR + crc + SEPERATOR + data super(msg) end
send_heatbeat(url)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 156 def send_heatbeat(url) send_json({:hb => url}) end
send_json(d)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 11 def send_json(d) send_data(JSON.dump(d.is_a?(String) ? {:d => d} : d)) end
send_msg(m)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 130 def send_msg(m) send_json({:m => m}) end
send_msg_bcast(m)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 127 def send_msg_bcast(m) send_json({:mb => m}) end
send_prompt(p)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 124 def send_prompt(p) send_json({:p => p}) end
send_proxy_connection(url)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 163 def send_proxy_connection(url) send_json({:pc => url}) end
send_raw(l)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 142 def send_raw(l) send_json(l) end
send_register_server(url, name)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 150 def send_register_server(url, name) send_json({:rs => [url, name]}) end
send_server_list(list = nil)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 159 def send_server_list(list = nil) send_json({:sl => list}) end
send_shell_cmd(c)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 133 def send_shell_cmd(c) send_json({:s => c}) end
send_shell_result(r)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 136 def send_shell_result(r) send_json({:sc => r}) end
send_start_tls()
click to toggle source
# File lib/pry-remote-em/proto.rb, line 146 def send_start_tls send_json({:tls => true}) end
send_unregister_server(url)
click to toggle source
# File lib/pry-remote-em/proto.rb, line 153 def send_unregister_server(url) send_json({:urs => url}) end