Commit Graph

148 Commits

Author SHA1 Message Date
David Nadoba c2e373fec5
Adopt `Sendable` (#155)
* Adopt `Sendable`

* Workaround Swift 5.4 compiler bug
2022-08-31 16:22:32 +01:00
Cory Benfield 4e02d9cf35
Use Docc for documentation (#154)
Motivation

Documentation is nice, and we can help support users by providing useful
clear docs.

Modifications

Add Docc to 5.6 and later builds
Make sure symbol references work
Add overview docs

Result

Nice rendering docs
2022-07-29 15:02:01 +01:00
David Nadoba 94645c8fcd
Use `swift-atomics` instead of `NIOAtomics` (#153) 2022-07-07 17:50:28 +01:00
Cory Benfield 605f7a4c55
Add defensive lifetime management for security metadata (#152)
Motivation:

Right now we're playing a little fast and loose with the lifetimes of
the sec_protocol_metadata_t. As a practical matter it is highly likely
that this is owned (and so kept alive by) the NWConnection, but rather
than risk that we should tighten up the lifetime management.

Modifications:

Use withExtendedLifetime to extend the lifetime.

Result:

Better lifetime management.
2022-07-05 09:25:11 +01:00
Cory Benfield acb6425a09
Use 5.7 nightlies. (#151) 2022-06-13 04:04:36 -07:00
George Barnett 2cb54f91dd
Remove outdated docs from README (#150)
Motivation:

We no longer support Cocoapods and `swift package generate-xcodeproj` is
deprecated, so we shouldn't advertise their usage in the README.

Modifications:

Remove Cocoapods and `swift package generate-xcodeproj` sections from
the README.

Result:

More up-to-date README
2022-06-09 14:46:12 +01:00
Cory Benfield 7d09200afa
Don't close when waiting unless we were asked to. (#149)
Motivation:

When we're waiting for connectivity, the user might tell us that they
aren't interested in waiting. In that case we take advantage of the
signal and close early.

However, the code as-written had a bug: we didn't care whether the user
told us they _didn't_ want to wait, or they _did_: we just closed
because they had an opinion! That's no good! We should only close if
they don't want to wait.

Modifications:

- Only close if the user doesn't want to wait.
- Add tests

Result:

We won't close if users don't want us to.
2022-06-07 14:36:37 +01:00
František Mikš e90ac29391
change NIOTSNetworkEvent initializers visibility to pubilc level (#148) 2022-06-06 03:35:54 -07:00
Cory Benfield 5a7a9b7875
Tweak testConnectingInvolvesWaiting to avoid invoking Private Relay (#146)
Motivation:

Private Relay kicks in to secure unencrypted data transfers, and
connections to port 80 are a good signal. As a result, the current
construction of this test will invoke Private Relay and attempt to route
over it.

While Private Relay is in beta this is a bad outcome, as it risks
causing bugs in unusual network scenarios. So let's tell Private Relay
we don't need it.

Modifications:

Pretend we're gonna connect to 443 instead.

Result:

More reliable test.
2022-05-25 07:41:33 -07:00
George Barnett 936bc0487a
Remove build_podspec.sh (#144)
Motivation:

We no longer support Cocoapods

Modifications:

- Remove build_podspec.sh

Result:

Fewer unused files
2022-05-04 11:03:16 +01:00
George Barnett cf4cd97ec2
Update podspec script (#143)
Motivation:

To workaround https://github.com/apple/swift-nio/issues/2073 we must
list all transitive dependencies when building podspecs.

Modifications:

- Include transitive dependencies in the build_podspec script
- The list of dependencies was generated using
  the `list_transitive_dependencies.py` from the NIO repo.

Result:

Podspec generation script includes transitive dependencies.
2022-05-03 09:58:06 +01:00
Fabian Fett 1a4692acb8
Fix warnings, that appeared after requiring Swift 5.4 (#142) 2022-04-21 09:12:31 -07:00
Fabian Fett b559a7303a
Drop support for Swift 5.2 and 5.3 (#141)
As outlined in a [Swift forums post in November ’21](https://forums.swift.org/t/swiftnio-swift-version-support/53232), SwiftNIO will only support the latest non-patch Swift release and the 2 immediately prior non-patch versions.

- drop support for Swift 5.2 and 5.3. 
- update CI for Swift 5.4 to run on bionic instead of focal to ensure that we still test bionic. 
- add a CI job for Swift 5.7
2022-04-20 08:54:39 +02:00
Cory Benfield 22d92ad93c
Add 5.6 nightly CI (#140)
* Add 5.6 nightly CI

The 5.6 nightly images are available, let's use them.

* Add 5.5 as well
2022-01-18 09:37:53 +00:00
George Barnett 8ab824b140
Explicitly retain timer source when scheduling tasks (#138)
Motivation:

When a task is scheduled using a `DispatchTimerSource` on a `NIOTSEventLoop`
the source is retain via a callback on the promise associated with the
scheduled task. This stops the source from deinit'd before the task is
run. However, the callback being added is an implementation details of
`Scheduled` and the retain cycle is incidental.

If that detail chnaged (such as in
https://github.com/apple/swift-nio/pull/2011) then tasks may not run and
the promise could be leaked.

Modifications:

- Explicitly add a retain cycle between the future and the timer source
  which is broken by the promise being completed and callbacks run.

Result:

The timer source is kept alive until the event fires.
2022-01-12 10:37:50 +00:00
Cory Benfield e7f5278a26
Clean up imports and dependencies. (#130)
Motivation:

With NIO 2.32.0 we broke the core NIO module up into modules that split
apart the POSIX layer and the core abstractions. As a result, this
package no longer needs to express a hard dependency on the POSIX layer.

Modifications:

- Rewrote imports of NIO to NIOCore.
- Added NIOEmbedded imports where necessary in tests.
- Note that the main package still _depends_ on NIO, which is necessary
  for backwards-compatibility reasons. This dependency is unused.

Result:

No need to use NIOPosix.
2021-09-14 10:06:42 +01:00
Peter Adams 9571a61d23
Move check for event loop shutdown into taskQueue (#127)
Motivation:

The event loop state is not protected for access on different threads.
This means it must only be accessed from the task queue.

Modifications:

Move check for event loop shutdown into taskQueue

Result:

Event Loop state only accessed from the task queue.
2021-08-19 10:57:47 +01:00
George Barnett 5fd5ba4d3e
Use non-deprecated API for removing handlers (#125)
Motivation:

`removeHandlers(channel:)` was deprecated in NIO 2.32.0.

Modifications:

- Raise minimum required NIO version to 2.32.0
- Use `removeHandlers(pipeline:)`

Result:

We don't use deprecated API.
2021-08-17 18:01:25 +01:00
David Evans 39587bcecc
Update NIO to 2.30 (#123) 2021-06-23 14:16:15 +01:00
David Evans 0aecfe8b3a
Remove Swift 5.0 and 5.1 support, and add CI config (#122)
* Setup CI and update Package

* Rename sanity to soundness

* Apply suggestions from code review

Co-authored-by: Cory Benfield <lukasa@apple.com>

* Fix nightly docker config

Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-06-23 08:57:00 +01:00
Johannes Weiss 188a295ee3
docker setup for main nightlies (#114) 2021-06-22 18:47:35 +01:00
Johannes Weiss 47fddadf83
stop publishing the executable products (#119) 2021-06-08 14:04:45 +01:00
George Barnett 657537c2cf
Add support for syncOptions to NIOTSListenerChannel and NIOTSConnectionChannel (#117)
Motivation:

NIO 2.27.0 added optional support for synchronous channel options.
NIOTSListenerChannel and NIOTSConnectionChannel should support this.

Modifications:

- Add synchronous options for NIOTSConnectionChannel and
  NIOTSListenerChannel
- Avoid an allocation in 'getOption' for each channel if the caller is
  already on the right event loop by using 'makeSucceededFuture'
- Remove a no longer used internal function and an already dead private
  helper

Result:

- Support for sync options and fewer allocations
2021-03-16 08:38:47 +00:00
George Barnett b9fd95b8d5
Add SECURITY.md (#116) 2021-03-09 11:14:29 +00:00
Johannes Weiss 1d28d48e07
update code of conduct to version 1.4 (#115) 2021-02-17 14:16:51 +00:00
Cory Benfield 5c90846c1b
Tolerate out-of-band ports. (#112)
Motivation:

We shouldn't crash if the user gives us a bad port.

Modifications:

- Check the ports are in-band before we move on.

Result:

We won't crash.
2021-01-27 14:37:00 +00:00
George Barnett 9fc0d32e07
Remove a redundant availability check (#109)
Motivation:

xcodebuild complains during Cocapods validation (which fails as a
result) about a redundant availability check. It's redundant because for
watchOS the availability guard on the outer scope has the same
conditions (for other platforms the conditions are tighter in the
inner scope). We never hit this before because we only recently added
watchOS to the supported platforms for Cocapods.

Modifications:

- Remove a redundant availability check

Result:

- Cocapods can validate without error
2020-11-27 09:27:39 +00:00
Cory Benfield 5a352330c0
Remove agressive precondition in zero-length-writes. (#108)
Motivation:

The zero-length writes handler will crash if it receives channelInactive
before channelActive. Sadly, that's totally possible if a channel is
closed from the connect promise.

Modifications:

- Tone back the preconditions a bit.
- Add a test that triggers this path.

Result:

Channel handler behaves better on early close
2020-11-24 13:21:50 +00:00
George Barnett 18c17b9ae0
Add watchOS deployment to PodSpec build script (#107)
Motivation:

We support watchOS 6+ with SwiftNIO Transport Services; as such we should
include watchOS as a deployment target for our CocoaPods.

Modifications:

- Add a watchOS deployment target to `build_podspecs.sh`

Result:

Users can deploy to watchOS 6+ with CocoaPods.
2020-10-19 10:11:40 +01:00
Cory Benfield 698e0eed47
We use the main branch now. (#105) 2020-09-24 16:28:15 +01:00
Cory Benfield bb56586c4c
Avoid crashing when connecting to empty host. (#103)
Motivation:

Network.framework will crash when we attempt to connect to the host
string "". That's not ideal, so we should detect that case and avoid it.

Modifications:

- Add code to detect the empty host string.

Result:

No crashes when accidentally connecting to "".
2020-08-11 10:10:17 +01:00
Peter Adams 71dbab3f12
Fix docker shell to use correct image. (#102)
Motivation:

Docker shell was incorrectly using the swift-nio docker image
rather than the swift-nio-transport-services one.

Modifications:

Change docker compose file to use the correct image.

Result:

Correct image will be used for docker shell.
2020-08-04 09:23:12 +01:00
Peter Adams d40a5e34e5
Add docker config for swift-nio-transport-services (#99)
Motivation:

It's important that transport-services compiles and does nothing
on linux so it can be used in builds which just do the right thing
on all platforms.

Modifications:

Add basic docker-compose files based on those from swift-nio

Result:

It's possible to run docker on this repo to run the tests.
2020-07-24 08:39:46 +01:00
Peter Adams cd49a10c4f
Directly support the allowLocalEndpointReuse channel option (#82)
Motivation:

The NetworkFramework directly supports the concept of allowLocalEndPointReuse. Currently to get through the nio system, this is mapped to the SO_REUSEADDR option.

Now there is a shorthand option for this, it is sad to map from allowLocalEndPointReuse to SO_REUSEADDR and back again.

Modifications:

Add a new NIOTS channel option for this setting.
Set the underlying based on any of new setting, reuseAddr or reusePort.
Add a override to interpret the shorthand option directly into the new option.
Add shorthand options for client with tests of equivalence to long options.

Result:

Behaviour is identical but we can feel happier that the option mapping is less confusing.
2020-07-01 14:51:31 +01:00
Cory Benfield f9a95e9bbb
Update watchOS availability. (#98)
Motivation:

In a patch where we added some metadata options, we accidentally set the
availability wrong. This is a compile-time error, so we broke watchOS
compilation.

Modifications:

Update the availability of some types on watchOS.

Result:

Users can build on watchOS again.
2020-06-19 10:19:47 +01:00
Johannes Weiss 9f7dff10ad
silence #file to #filePath differently (#96)
Motivation:

only works if done when _calling_ a function, not when defining one :|.

- https://github.com/apple/swift/pull/32445
- https://bugs.swift.org/browse/SR-12936
- https://bugs.swift.org/browse/SR-12934
- https://bugs.swift.org/browse/SR-13041

Modifications:

Silence #file to #filePath differently.

Result:

Hopefully at some point we get this working.
2020-06-18 13:09:01 +01:00
George Barnett 7eeb0ca94c
Update build_podspec.sh to not use exact dependency versions (#93)
Motivation:

The build_podspec.sh script generates a podspec which requires exact
versions of its dependencies. This very quickly turns into unresolvable
dependency graphs.

Modifications:

NIO version passed to script must be in the format MAJOR.MINOR
Podspec dependencies are now '>= MAJOR.MINOR', '< MAJOR+1'

Result:

Looser version requirements for podspecs
2020-06-17 13:07:45 +01:00
Cory Benfield 2937017e27
Add user event fired when waiting for connectivity. (#95)
Motivation:

On Apple's devices it is considered a best practice to wait for network
connectivity in cases when a connection request cannot immediately be
satisfied, rather than erroring out. This reflects the dynamic and fluid
network environment on Apple devices, with their many network interfaces
and complex interactions between radios, VPNs, and network devices.

While NIOTS supports this model of interaction (and indeed uses it out
of the box), and supports configuring it (by setting
`NIOTSChannelOptions.waitForActivity`), a key pillar is missing:
observability. Right now we don't actually _tell_ the user when we're
waiting for connectivity. This makes it difficult to act on this
information.

Modifications:

- Added a user event, `NIOTSNetworkEvents.WaitingForConnectivity` that
  is fired when connectivity could not be established, but the situation
  may change in future.

Result:

Our users can tell their users when they're waiting for something!
2020-06-17 09:38:07 +01:00
Johannes Weiss 2ac8fde712
silence #file to #filePath warning (#91) 2020-06-08 17:50:28 +01:00
Pasi Salenius 7e330732f2
New channel options exposing properties of underlying NWConnection (#90)
* Initial draft implementation of new channel options for NWConnection.currentPath, metadata for a given NWProtocol, establishment report and data transfer report. Add a new error for not existing connection. Add tests for all of these. The data transfer report option has to be implemented in another way, as the collection of the final data transfer report does not seem very straightforward.

* Fix incorrect available attributes. Make the Value of NIOTSEstablishmentReportOption an EventLoopFuture returning an optional report. Move handling of NIOTSEstablishmentReportOption and NIOTSDataTransferReportOption to getOption0. Remove nwConnection0().

* Use full type on currentPath too.

* Add a DispatchQueue to do collect of the pending data transfer report, use a DispatchGroup to wait for completion of report collection. Remove redundant attribute. Fix nits related to spacing and file header.

* Fix available attributes for tests too.
2020-06-01 11:52:56 +01:00
George Barnett 998422e195
Add a note about failing child channel initializers (#89)
Motivation:

It's not obvious what happens when `childChannelInitializer` returns a
failed future. See https://github.com/apple/swift-nio/pull/1516

Modifications:

Add a note to the `childChannelInitializer` documentation.

Result:

Better docs.
2020-05-15 13:50:44 +01:00
George Barnett aac0780fef
Add supported platforms to README (#87)
Motivation:

We have a weird availability model for NIOTS since we can build it even
if Network.framework isn't available: we don't document this anywhere.

Modifications:

Explain supported platform model in the README.

Result:

Better documentation.
2020-05-15 13:49:35 +01:00
Gwynne Raskind 4eb9bebfb8
Per additional discussion and feedback in apple/swift-nio#1508, we're removing the message parameter from the precondition assertion methods entirely. Added a couple of missing @inlinables to match the declarations now present over there as well. (#85) 2020-05-07 12:50:39 +01:00
Gwynne Raskind fe7e340f41
Update `NIOTSEventLoop` per apple/swift-nio#1508 (#84)
Motivation:

See apple/swift-nio#1508 for rationale

Modifications:

Provides implementations of `preconditionInEventLoop(_:file:line:)` and `preconditionNotInEventLoop(_:file:line:)`.

Result:

NIOTSEventLoop will now use dispatchPrecondition(condition:) for the in/not in preconditions instead of relying on the default implementation, yielding improved correctness.
2020-05-07 10:27:27 +01:00
Peter Adams 7c74f62ea7
Deduplicate ChannelOptions.Storage. (#80) 2020-04-21 21:16:19 +01:00
Johannes Weiss 85a67aea7c
add missing canImport(Network) to tests (#78) 2020-04-03 18:23:25 +01:00
Adam Fowler 8228db3917
Add canImport(Network) to NIOTSBootstraps.swift (#77) 2020-04-03 18:16:51 +01:00
Johannes Weiss 409fddd45c
bootstraps: offer ELG validation (#76)
Motivation:

Today, we just expect the ELGs passed to the bootstraps to be the
correct ones, if not, we crash.

Modifications:

Offer an alternative validatingGroup: init that just returns nil
if the ELGs are of the wrong types.

Result:

Easier to work with multi-stack systems for example when the user might
pass an ELG for either NIO on Sockets or NIO on Network.framework.

This is the NIOTS companion for https://github.com/apple/swift-nio/pull/1464
2020-04-03 15:57:03 +01:00
Marcus Liotta 7f98392c5d
FilterEmptyWritesHandler (#72)
Add filter removing empty writes to remedy a bug in Network Framework. This is a work in progress, after some initial discussions and suggestions by @weissi.

Motivation:

There is a known bug in Network Framework affecting iOS devices, which will stall a TCP connection after an empty, zero length write. This bug is not found in Network Framework on MacOS. While the bug fix will be rolled out in future versions of iOS it may take some time. Also, to better support the current and older versions of iOS where the bug remains, @weissi suggested to add a ChannelOutboundHandler, that filters out empty writes.

Modifications:

Add a FilterEmptyWritesHandler, which on affected iOS versions can be added by default to all Channels.
Unit tests for all additions and modifications.

Result:

With this workaround NIOTransportServices can support all iOS versions with Network Framework.
2020-04-03 11:36:26 +01:00
Johannes Weiss cefc7014fc
fix license headers (#73) 2020-03-25 15:43:40 +00:00