class BBS::Gateway
A door to another telnet board, the telnet gateway of the old BBSes: the caller’s line is handed on to host:port as it is, and comes back when that board hangs up. The board on the other end runs its own code; this one only carries the bytes.
door :feedia, BBS::Gateway.new(host: 'feedia.example', port: 2323, name: 'Feedia'), label: '&Feedia'
Towards the other board the gateway is the telnet client: it answers its negotiation, reports the caller’s window size, and passes the caller’s later size changes on. A PETSCII line has no window size to report, so the other board takes it for a Commodore. Everything else goes through untouched both ways, mouse reports and PETSCII included.
A gateway is made for one address; a directory that dials many boards makes one a call, and reads how it went from the Report its block gets:
BBS::Gateway.new(host: 'bbs.example.org', port: 23).call(session) do |report| log(report.connected ? "#{report.received} bytes" : report.error.class) end
The host is resolved once and the call goes to that address, which by default must be on the public internet (BBS::Address.public?): a listing cannot make the board a relay into its own network. A board that dials its neighbours (host.docker.internal, a container) says public_only: false.
Constants
- BACK_WAIT
-
Seconds to wait for the caller’s key before the line goes back to the board.
- CONNECT_TIMEOUT
-
Seconds to wait for the other board to accept the connection, by default.
- FAILURES
-
The errors of a call that does not connect.
- Report
-
How one
callwent, given to its block.- connected
-
whether the other board accepted the connection
- error
-
the exception that kept it from connecting (SocketError when the name did not resolve,
Refusedfor an address that is not public, Errno::ECONNREFUSED, IO::TimeoutError or Errno::ETIMEDOUT …),nilwhen it connected - address
-
the IP address called, as a String;
nilwhen it did not connect - connect_seconds
-
how long the connection took to open, a Float;
nilwhen it did not connect - received
-
the bytes the other board sent the caller, telnet commands not counted
- hung_up
-
who ended the crossing:
:boardor:caller;nilwhen it did not connect
Attributes
The other board’s host name, its port as an Integer, and the name shown to the caller.
The other board’s host name, its port as an Integer, and the name shown to the caller.
The other board’s host name, its port as an Integer, and the name shown to the caller.
Public Class Methods
# File lib/bbs/gateway.rb, line 88 def initialize(host:, port:, name: nil, terminal: 'XTERM-256COLOR', connect_timeout: CONNECT_TIMEOUT, idle: nil, translate: false, public_only: true) @host = host @port = port.to_i @name = name || "#{host}:#{port}" @terminal = terminal @connect_timeout = connect_timeout @idle = idle @translate = translate @public_only = public_only end
Creates a gateway to host:port.
- name
-
the name shown to the caller; defaults to
host:port - terminal
-
the terminal type reported to the other board when it asks (not on a PETSCII line)
- connect_timeout
-
seconds to wait for the other board to accept the connection (
CONNECT_TIMEOUT) - idle
-
seconds the line may stay silent both ways before the call ends as if the caller hung up;
nilmeansBBS.config.idle_seconds, orBBS::Server::DEFAULT_TIMEOUTwhen that is not set - translate
-
whether a PETSCII caller gets the other board through an
AsciiBridge(a board for ASCII and ANSI terminals); the board then sees an ANSI terminal of the C64’s size. A modern caller’s line is never translated. - public_only
-
call only an address on the public internet (
BBS::Address.public?);falsefor a trusted neighbour such ashost.docker.internal
Public Instance Methods
# File lib/bbs/gateway.rb, line 112 def call(session, _context = {}) report = Report.new(connected: false, received: 0) remote = connect(session, report) or return raise IOError, 'the caller hung up' if carry(session, remote, report) back(session, "#{Ansi::RESET}#{Ansi::CRLF * 2} #{@name} hung up. Press a key to return.") ensure yield report if block_given? && report end
The door’s program: connects, carries the line until the other board hangs up, and waits for a key before the board takes the line back. A caller who hangs up meanwhile ends the call (IOError), and so does a line silent both ways for the idle seconds. When the other board does not answer or its address is refused, the caller is told so and the method returns after a key.
- session
-
the caller’s
BBS::Session - _context
-
the caller’s context; not used
With a block, yields a Report of the call once it is over (also when the caller hung up and the IOError is on its way).