2 tofuproxy -- flexible HTTP/HTTPS proxy, TLS terminator, X.509 TOFU
3 manager, WARC/geminispace browser
4 Copyright (C) 2021-2023 Sergey Matveev <stargrave@stargrave.org>
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 3 of the License.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
27 type SingleConn struct {
33 func (conn *SingleConn) Read(b []byte) (int, error) { return conn.conn.Read(b) }
35 func (conn *SingleConn) Write(b []byte) (int, error) { return conn.conn.Write(b) }
37 func (conn *SingleConn) Close() error {
38 conn.once.Do(conn.ln.Unlock)
39 return conn.conn.Close()
42 func (conn *SingleConn) LocalAddr() net.Addr { return conn.conn.LocalAddr() }
44 func (conn *SingleConn) RemoteAddr() net.Addr { return conn.conn.RemoteAddr() }
46 func (conn *SingleConn) SetDeadline(t time.Time) error { return conn.conn.SetDeadline(t) }
48 func (conn *SingleConn) SetReadDeadline(t time.Time) error { return conn.conn.SetReadDeadline(t) }
50 func (conn *SingleConn) SetWriteDeadline(t time.Time) error { return conn.conn.SetWriteDeadline(t) }
52 type AlreadyAccepted struct{}
54 func (err AlreadyAccepted) Error() string { return "already accepted" }
56 type SingleListener struct {
62 func (ln *SingleListener) Accept() (net.Conn, error) {
65 return nil, AlreadyAccepted{}
68 return &SingleConn{conn: ln.conn, ln: ln}, nil
71 func (ln *SingleListener) Close() error { return nil }
73 func (ln *SingleListener) Addr() net.Addr { return ln.conn.LocalAddr() }