Skip to content

Commit d16467d

Browse files
authored
Merge PSQLConnection into PostgresConnection (#240)
1 parent 43742ef commit d16467d

File tree

11 files changed

+405
-424
lines changed

11 files changed

+405
-424
lines changed

Sources/PostgresNIO/Connection/PostgresConnection.swift

Lines changed: 324 additions & 38 deletions
Large diffs are not rendered by default.

Sources/PostgresNIO/New/Connection State Machine/ConnectionStateMachine.swift

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -134,22 +134,37 @@ struct ConnectionStateMachine {
134134
}
135135

136136
mutating func connected(tls: TLSConfiguration) -> ConnectionAction {
137-
guard case .initialized = self.state else {
138-
preconditionFailure("Unexpected state")
139-
}
137+
switch self.state {
138+
case .initialized:
139+
switch tls {
140+
case .disable:
141+
self.state = .waitingToStartAuthentication
142+
return .provideAuthenticationContext
140143

141-
switch tls {
142-
case .disable:
143-
self.state = .waitingToStartAuthentication
144-
return .provideAuthenticationContext
144+
case .prefer:
145+
self.state = .sslRequestSent(.prefer)
146+
return .sendSSLRequest
145147

146-
case .prefer:
147-
self.state = .sslRequestSent(.prefer)
148-
return .sendSSLRequest
148+
case .require:
149+
self.state = .sslRequestSent(.require)
150+
return .sendSSLRequest
151+
}
149152

150-
case .require:
151-
self.state = .sslRequestSent(.require)
152-
return .sendSSLRequest
153+
case .sslRequestSent,
154+
.sslNegotiated,
155+
.sslHandlerAdded,
156+
.waitingToStartAuthentication,
157+
.authenticating,
158+
.authenticated,
159+
.readyForQuery,
160+
.extendedQuery,
161+
.prepareStatement,
162+
.closeCommand,
163+
.error,
164+
.closing,
165+
.closed,
166+
.modifying:
167+
return .wait
153168
}
154169
}
155170

@@ -1084,7 +1099,7 @@ extension ConnectionStateMachine {
10841099
case .tooManyParameters:
10851100
return true
10861101
case .connectionQuiescing:
1087-
preconditionFailure("Pure client error, that is thrown directly in PSQLConnection")
1102+
preconditionFailure("Pure client error, that is thrown directly in PostgresConnection")
10881103
case .connectionClosed:
10891104
preconditionFailure("Pure client error, that is thrown directly and should never ")
10901105
case .connectionError:

Sources/PostgresNIO/New/Extensions/Logging+PSQL.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
import Logging
22

3+
@usableFromInline
4+
enum PSQLConnection {}
5+
36
extension PSQLConnection {
47
@usableFromInline
58
enum LoggerMetaDataKey: String {

Sources/PostgresNIO/New/PSQLChannelHandler.swift

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ final class PSQLChannelHandler: ChannelDuplexHandler {
2626
private var rowStream: PSQLRowStream?
2727
private var decoder: NIOSingleStepByteToMessageProcessor<PSQLBackendMessageDecoder>
2828
private var encoder: BufferedMessageEncoder!
29-
private let configuration: PSQLConnection.Configuration
29+
private let configuration: PostgresConnection.Configuration
3030
private let configureSSLCallback: ((Channel) throws -> Void)?
3131

3232
/// this delegate should only be accessed on the connections `EventLoop`
3333
weak var notificationDelegate: PSQLChannelHandlerNotificationDelegate?
3434

35-
init(configuration: PSQLConnection.Configuration,
35+
init(configuration: PostgresConnection.Configuration,
3636
logger: Logger,
3737
configureSSLCallback: ((Channel) throws -> Void)?)
3838
{
@@ -45,7 +45,7 @@ final class PSQLChannelHandler: ChannelDuplexHandler {
4545

4646
#if DEBUG
4747
/// for testing purposes only
48-
init(configuration: PSQLConnection.Configuration,
48+
init(configuration: PostgresConnection.Configuration,
4949
state: ConnectionStateMachine = .init(.initialized),
5050
logger: Logger = .psqlNoOpLogger,
5151
configureSSLCallback: ((Channel) throws -> Void)?)
@@ -518,7 +518,7 @@ extension PSQLChannelHandler: PSQLRowsDataSource {
518518
}
519519
}
520520

521-
extension PSQLConnection.Configuration.Authentication {
521+
extension PostgresConnection.Configuration.Authentication {
522522
func toAuthContext() -> AuthContext {
523523
AuthContext(
524524
username: self.username,
@@ -575,7 +575,7 @@ private extension Insecure.MD5.Digest {
575575
}
576576

577577
extension ConnectionStateMachine.TLSConfiguration {
578-
fileprivate init(_ connection: PSQLConnection.Configuration.TLS) {
578+
fileprivate init(_ connection: PostgresConnection.Configuration.TLS) {
579579
switch connection.base {
580580
case .disable:
581581
self = .disable
@@ -589,7 +589,7 @@ extension ConnectionStateMachine.TLSConfiguration {
589589

590590
extension PSQLChannelHandler {
591591
convenience init(
592-
configuration: PSQLConnection.Configuration,
592+
configuration: PostgresConnection.Configuration,
593593
configureSSLCallback: ((Channel) throws -> Void)?)
594594
{
595595
self.init(

0 commit comments

Comments
 (0)