-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add the NFS3 protocol #155
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
bccb7ab
add the NFS3 protocol
weissi a9214f2
make writes return the amount of bytes written
weissi b3cbc70
nits, docs, removes
weissi 3a8612f
compiler errors on old swifts
weissi b483131
Hashable everything
weissi c158372
delay errors
weissi 7900976
remove typealiases
weissi f0375d3
Sendables
weissi 2c9f2cf
implicit endiannes
weissi 6c47a10
more changes
weissi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.") | ||
glbrntt marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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 { | ||
glbrntt marked this conversation as resolved.
Show resolved
Hide resolved
weissi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are we intentionally not defining a product here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Lukasa for now, yes. In a follow-up I might either add a product (either
NIONFS3
or_NIONFS3Preview
) but we can discuss then. I want to first land the bulk of the code