-
Notifications
You must be signed in to change notification settings - Fork 82
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add the NFS3 protocol * make writes return the amount of bytes written * nits, docs, removes * compiler errors on old swifts * Hashable everything * delay errors * remove typealiases * Sendables * implicit endiannes * more changes
- Loading branch information
Showing
36 changed files
with
4,581 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021-2023 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import NIOCore | ||
|
||
// MARK: - Mount | ||
public struct MountCallMount: Hashable & Sendable { | ||
public init(dirPath: String) { | ||
self.dirPath = dirPath | ||
} | ||
|
||
public var dirPath: String | ||
} | ||
|
||
public struct MountReplyMount: Hashable & Sendable { | ||
public init(result: NFS3Result<MountReplyMount.Okay, NFS3Nothing>) { | ||
self.result = result | ||
} | ||
|
||
public struct Okay: Hashable & Sendable { | ||
public init(fileHandle: NFS3FileHandle, authFlavors: [RPCAuthFlavor] = [.unix]) { | ||
self.fileHandle = fileHandle | ||
self.authFlavors = authFlavors | ||
} | ||
|
||
public var fileHandle: NFS3FileHandle | ||
public var authFlavors: [RPCAuthFlavor] = [.unix] | ||
} | ||
|
||
public var result: NFS3Result<Okay, NFS3Nothing> | ||
} | ||
|
||
extension ByteBuffer { | ||
public mutating func readNFS3CallMount() throws -> MountCallMount { | ||
let dirPath = try self.readNFS3String() | ||
return MountCallMount(dirPath: dirPath) | ||
} | ||
|
||
@discardableResult public mutating func writeNFS3CallMount(_ call: MountCallMount) -> Int { | ||
self.writeNFS3String(call.dirPath) | ||
} | ||
|
||
@discardableResult public mutating func writeNFS3ReplyMount(_ reply: MountReplyMount) -> Int { | ||
var bytesWritten = self.writeNFS3ResultStatus(reply.result) | ||
|
||
switch reply.result { | ||
case .okay(let reply): | ||
bytesWritten += self.writeNFS3FileHandle(reply.fileHandle) | ||
precondition(reply.authFlavors == [.unix] || reply.authFlavors == [.noAuth], | ||
"Sorry, anything but [.unix] / [.system] / [.noAuth] unimplemented.") | ||
bytesWritten += self.writeInteger(UInt32(reply.authFlavors.count), as: UInt32.self) | ||
for flavor in reply.authFlavors { | ||
bytesWritten += self.writeInteger(flavor.rawValue, as: UInt32.self) | ||
} | ||
case .fail(_, _): | ||
() | ||
} | ||
|
||
return bytesWritten | ||
} | ||
|
||
public mutating func readNFS3ReplyMount() throws -> MountReplyMount { | ||
let result = try self.readNFS3Result(readOkay: { buffer -> MountReplyMount.Okay in | ||
let fileHandle = try buffer.readNFS3FileHandle() | ||
let authFlavors = try buffer.readNFS3List(readEntry: { buffer in | ||
try buffer.readRPCAuthFlavor() | ||
}) | ||
return MountReplyMount.Okay(fileHandle: fileHandle, authFlavors: authFlavors) | ||
|
||
}, | ||
readFail: { _ in NFS3Nothing() }) | ||
return MountReplyMount(result: result) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021-2023 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import NIOCore | ||
|
||
// MARK: - Null | ||
public struct MountCallNull: Hashable & Sendable { | ||
public init() {} | ||
} | ||
|
||
extension ByteBuffer { | ||
public mutating func readMountCallNull() throws -> MountCallNull { | ||
return MountCallNull() | ||
} | ||
|
||
@discardableResult public mutating func writeMountCallNull(_ call: MountCallNull) -> Int { | ||
return 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021-2023 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import NIOCore | ||
|
||
// MARK: - Unmount | ||
public struct MountCallUnmount: Hashable & Sendable { | ||
public init(dirPath: String) { | ||
self.dirPath = dirPath | ||
} | ||
|
||
public var dirPath: String | ||
} | ||
|
||
public struct MountReplyUnmount: Hashable & Sendable { | ||
public init() {} | ||
} | ||
|
||
extension ByteBuffer { | ||
public mutating func readNFS3CallUnmount() throws -> MountCallUnmount { | ||
let dirPath = try self.readNFS3String() | ||
return MountCallUnmount(dirPath: dirPath) | ||
} | ||
|
||
@discardableResult public mutating func writeNFS3CallUnmount(_ call: MountCallUnmount) -> Int { | ||
self.writeNFS3String(call.dirPath) | ||
} | ||
|
||
@discardableResult public mutating func writeNFS3ReplyUnmount(_ reply: MountReplyUnmount) -> Int { | ||
return 0 | ||
} | ||
|
||
public mutating func readNFS3ReplyUnmount() throws -> MountReplyUnmount { | ||
return MountReplyUnmount() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021-2023 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import NIOCore | ||
|
||
public struct NFS3CallDecoder: NIOSingleStepByteToMessageDecoder { | ||
public typealias InboundOut = RPCNFS3Call | ||
|
||
public init() {} | ||
|
||
public mutating func decode(buffer: inout ByteBuffer) throws -> RPCNFS3Call? { | ||
guard let message = try buffer.readRPCMessage() else { | ||
return nil | ||
} | ||
|
||
guard case (.call(let call), var body) = message else { | ||
throw NFS3Error.wrongMessageType(message.0) | ||
} | ||
|
||
return try body.readNFS3Call(rpc: call) | ||
} | ||
|
||
public mutating func decodeLast(buffer: inout ByteBuffer, seenEOF: Bool) throws -> RPCNFS3Call? { | ||
return try self.decode(buffer: &buffer) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//===----------------------------------------------------------------------===// | ||
// | ||
// This source file is part of the SwiftNIO open source project | ||
// | ||
// Copyright (c) 2021-2023 Apple Inc. and the SwiftNIO project authors | ||
// Licensed under Apache License v2.0 | ||
// | ||
// See LICENSE.txt for license information | ||
// See CONTRIBUTORS.txt for the list of SwiftNIO project authors | ||
// | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
import NIOCore | ||
|
||
public struct NFS3CallEncoder: MessageToByteEncoder { | ||
public typealias OutboundIn = RPCNFS3Call | ||
|
||
public init() {} | ||
|
||
public func encode(data: RPCNFS3Call, out: inout ByteBuffer) throws { | ||
out.writeRPCNFS3Call(data) | ||
} | ||
} |
Oops, something went wrong.