Module: ShadowsocksRuby::Protocols::DummyHelper

Overview

This module include helper methods for a Packet/Cipher/Obfs Protocol.

To simplify boring long method name writing (eg: tcp_receive_from_client, tcp_send_to_client), two Adapter method are introduced and could be untilized: #async_recv and #send_data, they will be adapted to long method names (eg: tcp_receive_from_client, tcp_send_to_client) at runtime.

This helper module implement dummy #async_recv and #send_data, do nothing but just raise, in order to make things clear.

To use it, use include DummyHelper to include it into your protocol implementation.

Instance Method Summary collapse

Instance Method Details

#async_recv(n) ⇒ String

Receive n bytes of data @param n length of data to receive

Returns:

  • (String)

    Should return real data on runtime

Raises:

  • ProtocolError



62
63
64
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 62

def async_recv n
  raise ProtocolError, "async_recv must be set before use"
end

#raise_me(*args) ⇒ Object

If user code don’t want to implement a method, it can call this to raise Error.

Raises:

  • UnimplementError



75
76
77
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 75

def raise_me *args
  raise UnimplementError, "Some day may implement this: " + caller[0][/`.*'/][1..-2]
end

#send_data(data) ⇒ Object

Send data @param data data to send

Raises:

  • ProtocolError



69
70
71
# File 'lib/shadowsocks_ruby/protocols/protocol.rb', line 69

def send_data data
  raise ProtocolError, "send_data must be set before use"
end