Skip to content

Commit 6eebfac

Browse files
committed
formatted
1 parent b8d0bc9 commit 6eebfac

11 files changed

+547
-411
lines changed

Package.swift

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,37 +19,40 @@ let package = Package(
1919
name: "swift-libp2p-mplex",
2020
platforms: [
2121
.macOS(.v10_15),
22-
.iOS(.v13)
22+
.iOS(.v13),
2323
],
2424
products: [
2525
// Products define the executables and libraries a package produces, and make them visible to other packages.
2626
.library(
2727
name: "LibP2PMPLEX",
28-
targets: ["LibP2PMPLEX"]),
28+
targets: ["LibP2PMPLEX"]
29+
)
2930
],
3031
dependencies: [
3132
// Dependencies declare other packages that this package depends on.
32-
33+
3334
// LibP2P Core Modules
3435
.package(url: "https://github.com/swift-libp2p/swift-libp2p.git", .upToNextMinor(from: "0.1.0")),
35-
36+
3637
// NIO Test Utils
3738
.package(url: "https://github.com/apple/swift-nio.git", from: "2.0.0"),
38-
39+
3940
],
4041
targets: [
4142
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
4243
// Targets can depend on other targets in this package, and on products in packages this package depends on.
4344
.target(
4445
name: "LibP2PMPLEX",
4546
dependencies: [
46-
.product(name: "LibP2P", package: "swift-libp2p"),
47-
]),
47+
.product(name: "LibP2P", package: "swift-libp2p")
48+
]
49+
),
4850
.testTarget(
4951
name: "LibP2PMPLEXTests",
5052
dependencies: [
5153
"LibP2PMPLEX",
5254
.product(name: "NIOTestUtils", package: "swift-nio"),
53-
]),
55+
]
56+
),
5457
]
5558
)

Sources/LibP2PMPLEX/LibP2PMPLEX.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,32 +12,32 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15-
import NIO
1615
import LibP2P
1716
import LibP2PCore
17+
import NIO
1818

1919
protocol MessageExtractable {
2020
func messageBytes() -> ByteBuffer
2121
}
2222

23-
protocol MessageExtractableHandler:ChannelInboundHandler where InboundOut:MessageExtractable { }
23+
protocol MessageExtractableHandler: ChannelInboundHandler where InboundOut: MessageExtractable {}
2424

2525
public struct MPLEX: MuxerUpgrader {
26-
27-
public static let key:String = MPLEXStreamMultiplexer.protocolCodec
28-
let application:Application
26+
27+
public static let key: String = MPLEXStreamMultiplexer.protocolCodec
28+
let application: Application
2929

3030
public func upgradeConnection(_ conn: Connection, muxedPromise: EventLoopPromise<Muxer>) -> EventLoopFuture<Void> {
31-
return conn.channel.pipeline.addHandlers(
31+
conn.channel.pipeline.addHandlers(
3232
[
3333
ByteToMessageHandler(MPLEXFrameDecoder()),
3434
MessageToByteHandler(MPLEXFrameEncoder()),
35-
MPLEXStreamMultiplexer(connection: conn, muxedPromise: muxedPromise, supportedProtocols: [])
35+
MPLEXStreamMultiplexer(connection: conn, muxedPromise: muxedPromise, supportedProtocols: []),
3636
],
3737
position: .last
3838
)
3939
}
40-
40+
4141
public func printSelf() {
4242
application.logger.notice("Hi I'm MPLEX v6.7.0")
4343
}

Sources/LibP2PMPLEX/MPLEX/MPLEXErrorCode.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public struct MPLEXErrorCode {
3333
/// The underlying network representation of the error code.
3434
public var networkCode: Int {
3535
get {
36-
return Int(self._networkCode)
36+
Int(self._networkCode)
3737
}
3838
set {
3939
self._networkCode = UInt32(newValue)
@@ -93,9 +93,9 @@ public struct MPLEXErrorCode {
9393

9494
}
9595

96-
extension MPLEXErrorCode: Equatable { }
96+
extension MPLEXErrorCode: Equatable {}
9797

98-
extension MPLEXErrorCode: Hashable { }
98+
extension MPLEXErrorCode: Hashable {}
9999

100100
extension MPLEXErrorCode: CustomDebugStringConvertible {
101101
public var debugDescription: String {
@@ -129,28 +129,28 @@ extension MPLEXErrorCode: CustomDebugStringConvertible {
129129
}
130130
}
131131

132-
public extension UInt32 {
132+
extension UInt32 {
133133
/// Create a 32-bit integer corresponding to the given `MPLEXErrorCode`.
134-
init(mplexErrorCode code: MPLEXErrorCode) {
134+
public init(mplexErrorCode code: MPLEXErrorCode) {
135135
self = code._networkCode
136136
}
137137
}
138138

139-
public extension Int {
139+
extension Int {
140140
/// Create an integer corresponding to the given `MPLEXErrorCode`.
141-
init(mplexErrorCode code: MPLEXErrorCode) {
141+
public init(mplexErrorCode code: MPLEXErrorCode) {
142142
self = code.networkCode
143143
}
144144
}
145145

146-
public extension ByteBuffer {
146+
extension ByteBuffer {
147147
/// Serializes a `MPLEXErrorCode` into a `ByteBuffer` in the appropriate endianness
148148
/// for use in MPLEX.
149149
///
150150
/// - parameters:
151151
/// - code: The `MPLEXErrorCode` to serialize.
152152
/// - returns: The number of bytes written.
153-
mutating func write(mplexErrorCode code: MPLEXErrorCode) -> Int {
154-
return self.writeInteger(UInt32(mplexErrorCode: code))
153+
public mutating func write(mplexErrorCode code: MPLEXErrorCode) -> Int {
154+
self.writeInteger(UInt32(mplexErrorCode: code))
155155
}
156156
}

Sources/LibP2PMPLEX/MPLEX/MPLEXErrors.swift

Lines changed: 31 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,34 @@
2626
//
2727
//===----------------------------------------------------------------------===//
2828

29-
public protocol NIOMPLEXError: Equatable, Error { }
29+
public protocol NIOMPLEXError: Equatable, Error {}
3030

31-
public enum MuxerError:Error {
31+
public enum MuxerError: Error {
3232
case custom(String)
3333
}
3434

3535
/// Errors that NIO raises when handling MPLEX connections.
3636
public enum NIOMPLEXErrors {
3737

3838
public static func noSuchStream(streamID: MPLEXStreamID, file: String = #file, line: UInt = #line) -> NoSuchStream {
39-
return NoSuchStream(streamID: streamID, file: file, line: line)
39+
NoSuchStream(streamID: streamID, file: file, line: line)
4040
}
41-
42-
public static func streamClosed(streamID: MPLEXStreamID, errorCode: MPLEXErrorCode, file: String = #file, line: UInt = #line) -> StreamClosed {
43-
return StreamClosed(streamID: streamID, errorCode: errorCode, file: file, line: line)
41+
42+
public static func streamClosed(
43+
streamID: MPLEXStreamID,
44+
errorCode: MPLEXErrorCode,
45+
file: String = #file,
46+
line: UInt = #line
47+
) -> StreamClosed {
48+
StreamClosed(streamID: streamID, errorCode: errorCode, file: file, line: line)
4449
}
45-
50+
4651
public static func noStreamIDAvailable(file: String = #file, line: UInt = #line) -> NoStreamIDAvailable {
47-
return NoStreamIDAvailable(file: file, line: line)
52+
NoStreamIDAvailable(file: file, line: line)
4853
}
4954

5055
public static func streamError(streamID: MPLEXStreamID, baseError: Error) -> StreamError {
51-
return StreamError(streamID: streamID, baseError: baseError)
56+
StreamError(streamID: streamID, baseError: baseError)
5257
}
5358

5459
/// An attempt was made to issue a write on a stream that does not exist.
@@ -69,8 +74,8 @@ public enum NIOMPLEXErrors {
6974
self.location = _location(file: file, line: line)
7075
}
7176

72-
public static func ==(lhs: NoSuchStream, rhs: NoSuchStream) -> Bool {
73-
return lhs.streamID == rhs.streamID
77+
public static func == (lhs: NoSuchStream, rhs: NoSuchStream) -> Bool {
78+
lhs.streamID == rhs.streamID
7479
}
7580
}
7681

@@ -96,8 +101,8 @@ public enum NIOMPLEXErrors {
96101
self.location = _location(file: file, line: line)
97102
}
98103

99-
public static func ==(lhs: StreamClosed, rhs: StreamClosed) -> Bool {
100-
return lhs.streamID == rhs.streamID && lhs.errorCode == rhs.errorCode
104+
public static func == (lhs: StreamClosed, rhs: StreamClosed) -> Bool {
105+
lhs.streamID == rhs.streamID && lhs.errorCode == rhs.errorCode
101106
}
102107
}
103108

@@ -108,7 +113,7 @@ public enum NIOMPLEXErrors {
108113

109114
/// The location where the error was thrown.
110115
public var location: String {
111-
return _location(file: self.file, line: self.line)
116+
_location(file: self.file, line: self.line)
112117
}
113118

114119
@available(*, deprecated, renamed: "noStreamIDAvailable")
@@ -121,8 +126,8 @@ public enum NIOMPLEXErrors {
121126
self.line = line
122127
}
123128

124-
public static func ==(lhs: NoStreamIDAvailable, rhs: NoStreamIDAvailable) -> Bool {
125-
return true
129+
public static func == (lhs: NoStreamIDAvailable, rhs: NoStreamIDAvailable) -> Bool {
130+
true
126131
}
127132
}
128133

@@ -143,7 +148,7 @@ public enum NIOMPLEXErrors {
143148
}
144149

145150
func copy() -> Storage {
146-
return Storage(
151+
Storage(
147152
streamID: self.streamID,
148153
baseError: self.baseError
149154
)
@@ -160,7 +165,7 @@ public enum NIOMPLEXErrors {
160165

161166
public var baseError: Error {
162167
get {
163-
return self.storage.baseError
168+
self.storage.baseError
164169
}
165170
set {
166171
self.copyStorageIfNotUniquelyReferenced()
@@ -170,7 +175,7 @@ public enum NIOMPLEXErrors {
170175

171176
public var streamID: MPLEXStreamID {
172177
get {
173-
return self.storage.streamID
178+
self.storage.streamID
174179
}
175180
set {
176181
self.copyStorageIfNotUniquelyReferenced()
@@ -179,7 +184,7 @@ public enum NIOMPLEXErrors {
179184
}
180185

181186
public var description: String {
182-
return "StreamError(streamID: \(self.streamID), baseError: \(self.baseError))"
187+
"StreamError(streamID: \(self.streamID), baseError: \(self.baseError))"
183188
}
184189

185190
fileprivate init(streamID: MPLEXStreamID, baseError: Error) {
@@ -188,7 +193,6 @@ public enum NIOMPLEXErrors {
188193
}
189194
}
190195

191-
192196
/// This enum covers errors that are thrown internally for messaging reasons. These should
193197
/// not leak.
194198
internal enum InternalError: Error {
@@ -197,10 +201,10 @@ internal enum InternalError: Error {
197201
case codecError(code: MPLEXErrorCode)
198202
}
199203

200-
extension InternalError: Hashable { }
204+
extension InternalError: Hashable {}
201205

202206
private func _location(file: String, line: UInt) -> String {
203-
return "\(file):\(line)"
207+
"\(file):\(line)"
204208
}
205209

206210
private final class StringAndLocationStorage: Equatable {
@@ -209,7 +213,7 @@ private final class StringAndLocationStorage: Equatable {
209213
var line: UInt
210214

211215
var location: String {
212-
return _location(file: self.file, line: self.line)
216+
_location(file: self.file, line: self.line)
213217
}
214218

215219
init(_ value: String, file: String, line: UInt) {
@@ -219,11 +223,11 @@ private final class StringAndLocationStorage: Equatable {
219223
}
220224

221225
func copy() -> StringAndLocationStorage {
222-
return StringAndLocationStorage(self.value, file: self.file, line: self.line)
226+
StringAndLocationStorage(self.value, file: self.file, line: self.line)
223227
}
224228

225-
static func ==(lhs: StringAndLocationStorage, rhs: StringAndLocationStorage) -> Bool {
229+
static func == (lhs: StringAndLocationStorage, rhs: StringAndLocationStorage) -> Bool {
226230
// Only compare the value. The 'file' is not relevant here.
227-
return lhs.value == rhs.value
231+
lhs.value == rhs.value
228232
}
229233
}

0 commit comments

Comments
 (0)