func configureBootstrap()

in NIOSMTP/NIOSMTP/ViewController.swift [132:173]


func configureBootstrap(group: EventLoopGroup,
                        email: Email,
                        emailSentPromise: EventLoopPromise<Void>,
                        communicationHandler: @escaping (String) -> Void) throws -> NIOClientTCPBootstrap {
    let hostname = Configuration.shared.serverConfig.hostname
    let bootstrap: NIOClientTCPBootstrap

    switch (NetworkImplementation.best, Configuration.shared.serverConfig.tlsConfiguration) {
    case (.transportServices, .regularTLS), (.transportServices, .insecureNoTLS):
        if #available(macOS 10.14, iOS 12, tvOS 12, watchOS 3, *) {
            bootstrap = NIOClientTCPBootstrap(NIOTSConnectionBootstrap(group: group),
                                              tls: NIOTSClientTLSProvider())
        } else {
            fatalError("Network.framework unsupported on this OS yet it was selected as the best option.")
        }
    case (.transportServices, .startTLS):
        if #available(macOS 10.14, iOS 12, tvOS 12, watchOS 3, *) {
            bootstrap = try NIOClientTCPBootstrap(NIOTSConnectionBootstrap(group: group),
                                                  tls: NIOSSLClientTLSProvider(context: sslContext,
                                                                               serverHostname: hostname))
        } else {
            fatalError("Network.framework unsupported on this OS yet it was selected as the best option.")
        }
    case (.posix, _):
        bootstrap = try NIOClientTCPBootstrap(ClientBootstrap(group: group),
                                              tls: NIOSSLClientTLSProvider(context: sslContext,
                                                                           serverHostname: hostname))
    }

    switch Configuration.shared.serverConfig.tlsConfiguration {
    case .regularTLS:
        bootstrap.enableTLS()
    case .insecureNoTLS, .startTLS:
        () // no TLS to start with
    }

    return bootstrap.channelInitializer { channel in
        channel.pipeline.addHandlers(makeNIOSMTPHandlers(communicationHandler: communicationHandler,
                                                         email: email,
                                                         emailSentPromise: emailSentPromise))
    }
}