[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH v3 09/25] python/aqmp: add AsyncProtocol.accept() method
From: |
Eduardo Habkost |
Subject: |
Re: [PATCH v3 09/25] python/aqmp: add AsyncProtocol.accept() method |
Date: |
Thu, 19 Aug 2021 12:43:47 -0400 |
On Thu, Aug 19, 2021 at 11:48:16AM -0400, John Snow wrote:
> On Thu, Aug 19, 2021 at 10:50 AM Eric Blake <eblake@redhat.com> wrote:
>
> > On Wed, Aug 18, 2021 at 10:24:52AM -0400, John Snow wrote:
> > > > >
> > > > > + @upper_half
> > > > > + @require(Runstate.IDLE)
> > > > > + async def accept(self, address: Union[str, Tuple[str, int]],
> > > > > + ssl: Optional[SSLContext] = None) -> None:
> > > > > + """
> > > > > + Accept a connection and begin processing message queues.
> > > > > +
> > > > > + If this call fails, `runstate` is guaranteed to be set back
> > to
> > > > `IDLE`.
> > > > > +
> > > > > + :param address:
> > > > > + Address to listen to; UNIX socket path or TCP
> > address/port.
> > > >
> > > > Can't TCP use a well-known port name instead of an int? But limiting
> > > > clients to just int port for now isn't fatal to the patch.
> > > >
> > > >
> > > The old QMP library didn't support this, and I used the old library as my
> > > template here. I'm willing to change the address format and types to be
> > > more comprehensive, but I was thinking that it should probably try to
> > match
> > > or adhere to some standard; de-facto or otherwise. I wasn't sure which to
> > > pick, and we use a few different ones in QEMU itself. Any recommendations
> > > for me?
> >
> > I asked because I know QAPI specifies TCP as string/string (the
> > hostname as a string makes absolute sense, but the port number as a
> > string is because of the less-used feature of a well-known port name).
> > I'm fine if the initial patch uses an int for the port number here; we
> > can always add support for more formats down the road when someone
> > actually has a use for them.
> >
> >
> https://docs.python.org/3/library/socket.html#socket-families
>
> "A pair (host, port) is used for the AF_INET address family, where host is
> a string representing either a hostname in Internet domain notation like '
> daring.cwi.nl' or an IPv4 address like '100.50.200.5', and port is an
> integer."
>
> The docs seem to suggest that I am actually limited only to integers here.
> Do you have an example of using a string for a port number? I have to admit
> I am not well acquainted with it.
QEMU uses getaddrinfo() at inet_parse_connect_saddr() to translate the
string/string pair to a socket address.
Python equivalent:
>> socket.getaddrinfo('localhost', 'ssh')
[(<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>, 6, '', ('::1', 22,
0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_DGRAM: 2>, 17, '',
('::1', 22, 0, 0)), (<AddressFamily.AF_INET6: 10>, <SocketKind.SOCK_STREAM: 1>,
132, '', ('::1', 22, 0, 0)), (<AddressF
amily.AF_INET6: 10>, <SocketKind.SOCK_SEQPACKET: 5>, 132, '', ('::1', 22, 0,
0)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_STREAM: 1>, 6, '',
('127.0.0.1', 22)), (<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_DGRAM: 2>,
17, '', ('127.0.0.1', 22)), (<AddressFamily.AF_INE
T: 2>, <SocketKind.SOCK_STREAM: 1>, 132, '', ('127.0.0.1', 22)),
(<AddressFamily.AF_INET: 2>, <SocketKind.SOCK_SEQPACKET: 5>, 132, '',
('127.0.0.1', 22))]
Translating this to the correct arguments to socket.socket() and
socket.socket.connect() seems overly complicated, though.
--
Eduardo
- [PATCH v3 08/25] python/aqmp: add logging to AsyncProtocol, (continued)
[PATCH v3 10/25] python/aqmp: add configurable read buffer limit, John Snow, 2021/08/03
[PATCH v3 14/25] python/aqmp: add well-known QMP object models, John Snow, 2021/08/03
[PATCH v3 12/25] python/aqmp: add AsyncProtocol._readline() method, John Snow, 2021/08/03
[PATCH v3 13/25] python/aqmp: add QMP Message format, John Snow, 2021/08/03
[PATCH v3 15/25] python/aqmp: add QMP event support, John Snow, 2021/08/03
[PATCH v3 17/25] python/aqmp: add QMP protocol support, John Snow, 2021/08/03