Changeset 269 in code for trunk


Ignore:
Timestamp:
Apr 28, 2020, 9:41:13 AM (5 years ago)
Author:
delthas
Message:

Add support for IRC address schemes

This is preparatory work for adding other connection types to upstream
servers. The service command network create now accepts a scheme in
the address flag, which specifies how to connect to the upstream server.

The only supported scheme for now is ircs, which is also the default if
no scheme is specified. ircs connects to a network over a TLS TCP
connection.

Location:
trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/doc/soju.1.scd

    r264 r269  
    9494
    9595*network create* *-addr* <addr> [options...]
    96         Connect to a new network at _addr_. _-addr_ is mandatory. Other options are:
     96        Connect to a new network at _addr_. _-addr_ is mandatory.
     97
     98        _addr_ supports several connection types:
     99        - _[ircs://]host[:port]_ connects with TLS over TCP
     100
     101        Other options are:
    97102
    98103        *-name* <name>
  • trunk/service.go

    r263 r269  
    204204        }
    205205
     206        if addrParts := strings.SplitN(*addr, "://", 2); len(addrParts) == 2 {
     207                scheme := addrParts[0]
     208                switch scheme {
     209                case "ircs":
     210                default:
     211                        return fmt.Errorf("unknown scheme %q (supported schemes: ircs)", scheme)
     212                }
     213        }
     214
    206215        for _, command := range connectCommands {
    207216                _, err := irc.ParseMessage(command)
  • trunk/upstream.go

    r267 r269  
    6767        logger := &prefixLogger{network.user.srv.Logger, fmt.Sprintf("upstream %q: ", network.Addr)}
    6868
    69         addr := network.Addr
    70         if !strings.ContainsRune(addr, ':') {
    71                 addr = addr + ":6697"
     69        var scheme string
     70        var addr string
     71
     72        addrParts := strings.SplitN(network.Addr, "://", 2)
     73        if len(addrParts) == 2 {
     74                scheme = addrParts[0]
     75                addr = addrParts[1]
     76        } else {
     77                scheme = "ircs"
     78                addr = addrParts[0]
    7279        }
    7380
    7481        dialer := net.Dialer{Timeout: connectTimeout}
    7582
    76         logger.Printf("connecting to TLS server at address %q", addr)
    77         netConn, err := tls.DialWithDialer(&dialer, "tcp", addr, nil)
     83        var netConn net.Conn
     84        var err error
     85        switch scheme {
     86        case "ircs":
     87                if !strings.ContainsRune(addr, ':') {
     88                        addr = addr + ":6697"
     89                }
     90
     91                logger.Printf("connecting to TLS server at address %q", addr)
     92                netConn, err = tls.DialWithDialer(&dialer, "tcp", addr, nil)
     93        default:
     94                return nil, fmt.Errorf("failed to dial %q: unknown scheme: %v", addr, scheme)
     95        }
    7896        if err != nil {
    7997                return nil, fmt.Errorf("failed to dial %q: %v", addr, err)
Note: See TracChangeset for help on using the changeset viewer.