chitralverma commented on code in PR #7977:
URL: https://github.com/apache/opendal/pull/7977#discussion_r4758467865
##########
core/services/sftp/src/core.rs:
##########
@@ -15,40 +15,135 @@
// specific language governing permissions and limitations
// under the License.
+use std::borrow::Cow;
use std::fmt::Debug;
use std::future::Future;
use std::io;
use std::ops::Deref;
-use std::path::{Component, Path, PathBuf};
+use std::path::PathBuf;
use std::sync::Arc;
use asyncband::pool::{ManageObject, ObjectStatus, unbounded};
use asyncband::semaphore::{OwnedSemaphorePermit, Semaphore};
use log::debug;
use opendal_core::raw::*;
use opendal_core::*;
-use openssh::Error as SshError;
-use openssh::{KnownHosts, SessionBuilder};
-use openssh_sftp_client::Error as SftpClientError;
-use openssh_sftp_client::error::SftpErrorKind;
-use openssh_sftp_client::{Sftp, SftpOptions};
+use russh::client;
+use russh::keys::PrivateKeyWithHashAlg;
+use russh::keys::ssh_key::Algorithm;
+use russh::keys::ssh_key::HashAlg;
+use russh_sftp::client::RawSftpSession;
+use russh_sftp::client::error::Error as SftpClientError;
+use russh_sftp::client::rawsession::Limits;
+use russh_sftp::extensions;
+use russh_sftp::protocol::{FileAttributes, Handle, OpenFlags, SftpHandle,
SftpString, StatusCode};
+use url::Url;
+
+use super::known_hosts::HostKeyVerifier;
const POOL_CAPACITY: usize = 64;
+/// SSH handshakes that one pool runs at a time. OpenSSH starts to drop
+/// unauthenticated connections at 10 (`MaxStartups 10:30:100`).
+pub(crate) const MAX_CONCURRENT_HANDSHAKES: usize = 4;
+
+/// Payload limit of one read or write when the server does not send
+/// `[email protected]`. SFTP v3 servers must accept packets of 32 KiB.
+const DEFAULT_PAYLOAD_LEN: u64 = 32 * 1024;
+
+/// Bytes of a packet that a read or write request header can use. OpenSSH
+/// keeps the same distance between its packet and payload limits.
+const REQUEST_HEADER_LEN: u64 = 1024;
+
+const COPY_DATA: &str = "copy-data";
+
+/// SSH server address and login user parsed from the `endpoint` option.
+#[derive(Debug, Clone, PartialEq, Eq)]
+pub struct SshEndpoint {
+ pub user: Option<String>,
+ pub host: String,
+ pub port: u16,
+}
+
+impl SshEndpoint {
+ /// Parses `[user@]host[:port]` or `ssh://[user@]host[:port]`.
+ ///
+ /// The port defaults to 22. An IPv6 address must be in brackets.
+ pub fn parse(endpoint: &str) -> Result<Self> {
+ let invalid = |reason: &str| {
+ Error::new(
+ ErrorKind::ConfigInvalid,
+ format!("sftp endpoint is invalid: {reason}"),
+ )
+ .with_context("endpoint", endpoint)
Review Comment:
#9484 landed, so f37fe7835 merges `main`. I merged rather than rebased so
that the SHAs in these threads stay valid.
- `core.rs` keeps the russh version. `SftpCore` prints no endpoint, and
parse errors omit it. Authentication errors no longer name the user, because
the user can come from the endpoint.
- `endpoint_is_omitted_from_debug` keeps its assertions. The build now
rejects a password in the endpoint, so the test also checks that the error
omits it, and builds the service from an endpoint with only a user.
- `sshd_connection_error_omits_endpoint_userinfo` puts the marker in the
user name, because a password fails the build before any connection. It passes
against the fixture.
*This comment is AI assisted.*
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]