Skip to content
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

Proof of concept: Add really basically support for srv records. #178

Draft
wants to merge 1 commit into
base: 3.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions breezy/bzr/smart/medium.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
)
from breezy.i18n import gettext
from breezy.bzr.smart import client, protocol, request, signals, vfs
from breezy.transport import ssh
from breezy.transport import ssh, lookup_srv_single
""")
from ... import (
errors,
Expand Down Expand Up @@ -1029,9 +1029,9 @@ def _ensure_connection(self):
vendor = ssh._get_ssh_vendor()
else:
vendor = self._vendor
(host, port) = lookup_srv_single('_bzr+ssh._tcp', self._ssh_params.host, self._ssh_params.port)
self._ssh_connection = vendor.connect_ssh(self._ssh_params.username,
self._ssh_params.password, self._ssh_params.host,
self._ssh_params.port,
self._ssh_params.password, host, port,
command=[self._ssh_params.bzr_remote_path, 'serve', '--inet',
'--directory=/', '--allow-writes'])
io_kind, io_object = self._ssh_connection.get_sock_or_pipes()
Expand Down
18 changes: 18 additions & 0 deletions breezy/transport/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1629,6 +1629,24 @@ def do_catching_redirections(action, transport, redirected):
raise errors.TooManyRedirections


def lookup_srv_single(service, host, port=None):
"""Lookup a single host/port combination to connect to."""
try:
import dns.resolver
except ModuleNotFoundError:
mutter('dns.resolver not found, ignoring SRV record')
return (host, port)
srv_name = service + '.' + host
try:
srv_records = dns.resolver.query(srv_name, 'SRV')
except dns.resolver.NXDOMAIN:
mutter('srv record %s not found', srv_name)
return (host, port)
for srv in srv_records:
return (str(srv.target).rstrip('.'), port or srv.port)
return (host, port)


class Server(object):
"""A Transport Server.

Expand Down
7 changes: 5 additions & 2 deletions breezy/transport/sftp.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
FileFileStream,
_file_streams,
ssh,
lookup_srv_single,
ConnectedTransport,
)

Expand Down Expand Up @@ -407,8 +408,10 @@ def _create_connection(self, credentials=None):
auth = config.AuthenticationConfig()
user = auth.get_user('ssh', self._parsed_url.host,
self._parsed_url.port)
connection = vendor.connect_sftp(self._parsed_url.user, password,
self._parsed_url.host, self._parsed_url.port)
(host, port) = lookup_srv_single(
'_sftp._tcp', self._parsed_url.host, self._parsed_url.port)
connection = vendor.connect_sftp(
self._parsed_url.user, password, host, port)
return connection, (user, password)

def disconnect(self):
Expand Down