1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
// Copyright 2024 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

use explicit::UnreachableExt as _;
use netstack3_base::socket::MaybeDualStack;
use netstack3_base::{Uninstantiable, UninstantiableWrapper};

use crate::internal::datagram::{
    BoundSockets, DatagramBoundStateContext, DatagramIpSpecificSocketOptions,
    DatagramSocketMapSpec, DatagramSocketSpec, DualStackConverter, IpExt, IpOptions,
    NonDualStackConverter,
};
use crate::internal::spec_context::{
    DatagramSpecBoundStateContext, DualStackDatagramSpecBoundStateContext,
    NonDualStackDatagramSpecBoundStateContext,
};

impl<I: IpExt, S: DatagramSocketSpec, P: DatagramBoundStateContext<I, C, S>, C>
    DatagramSpecBoundStateContext<I, UninstantiableWrapper<P>, C> for S
{
    type IpSocketsCtx<'a> = P::IpSocketsCtx<'a>;
    type DualStackContext = P::DualStackContext;
    type NonDualStackContext = P::NonDualStackContext;
    fn dual_stack_context(
        core_ctx: &mut UninstantiableWrapper<P>,
    ) -> MaybeDualStack<&mut Self::DualStackContext, &mut Self::NonDualStackContext> {
        core_ctx.uninstantiable_unreachable()
    }
    fn with_bound_sockets<
        O,
        F: FnOnce(
            &mut Self::IpSocketsCtx<'_>,
            &BoundSockets<
                I,
                P::WeakDeviceId,
                <S as DatagramSocketSpec>::AddrSpec,
                <S as DatagramSocketSpec>::SocketMapSpec<I, P::WeakDeviceId>,
            >,
        ) -> O,
    >(
        core_ctx: &mut UninstantiableWrapper<P>,
        _cb: F,
    ) -> O {
        core_ctx.uninstantiable_unreachable()
    }
    fn with_bound_sockets_mut<
        O,
        F: FnOnce(
            &mut Self::IpSocketsCtx<'_>,
            &mut BoundSockets<
                I,
                P::WeakDeviceId,
                <S as DatagramSocketSpec>::AddrSpec,
                <S as DatagramSocketSpec>::SocketMapSpec<I, P::WeakDeviceId>,
            >,
        ) -> O,
    >(
        core_ctx: &mut UninstantiableWrapper<P>,
        _cb: F,
    ) -> O {
        core_ctx.uninstantiable_unreachable()
    }
    fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
        core_ctx: &mut UninstantiableWrapper<P>,
        _cb: F,
    ) -> O {
        core_ctx.uninstantiable_unreachable()
    }
}

impl<I: IpExt, S: DatagramSocketSpec, P: DatagramBoundStateContext<I, C, S>, C>
    NonDualStackDatagramSpecBoundStateContext<I, UninstantiableWrapper<P>, C> for S
{
    fn nds_converter(
        core_ctx: &UninstantiableWrapper<P>,
    ) -> impl NonDualStackConverter<I, P::WeakDeviceId, Self> {
        core_ctx.uninstantiable_unreachable::<Uninstantiable>()
    }
}

impl<I: IpExt, S: DatagramSocketSpec, P: DatagramBoundStateContext<I, C, S>, C>
    DualStackDatagramSpecBoundStateContext<I, UninstantiableWrapper<P>, C> for S
{
    type IpSocketsCtx<'a> = UninstantiableWrapper<P::IpSocketsCtx<'a>>;

    fn dual_stack_enabled(
        core_ctx: &UninstantiableWrapper<P>,
        _state: &impl AsRef<IpOptions<I, P::WeakDeviceId, S>>,
    ) -> bool {
        core_ctx.uninstantiable_unreachable()
    }

    fn to_other_socket_options<'a>(
        core_ctx: &UninstantiableWrapper<P>,
        _state: &'a IpOptions<I, P::WeakDeviceId, S>,
    ) -> &'a DatagramIpSpecificSocketOptions<I::OtherVersion, P::WeakDeviceId> {
        core_ctx.uninstantiable_unreachable()
    }

    fn ds_converter(
        core_ctx: &UninstantiableWrapper<P>,
    ) -> impl DualStackConverter<I, P::WeakDeviceId, S> {
        core_ctx.uninstantiable_unreachable::<Uninstantiable>()
    }

    fn to_other_bound_socket_id(
        core_ctx: &UninstantiableWrapper<P>,
        _id: &S::SocketId<I, P::WeakDeviceId>,
    ) -> <S::SocketMapSpec<I::OtherVersion, P::WeakDeviceId> as DatagramSocketMapSpec<
        I::OtherVersion,
        P::WeakDeviceId,
        S::AddrSpec,
    >>::BoundSocketId {
        core_ctx.uninstantiable_unreachable()
    }

    fn with_both_bound_sockets_mut<
        O,
        F: FnOnce(
            &mut Self::IpSocketsCtx<'_>,
            &mut BoundSockets<I, P::WeakDeviceId, S::AddrSpec, S::SocketMapSpec<I, P::WeakDeviceId>>,
            &mut BoundSockets<
                I::OtherVersion,
                P::WeakDeviceId,
                S::AddrSpec,
                S::SocketMapSpec<I::OtherVersion, P::WeakDeviceId>,
            >,
        ) -> O,
    >(
        core_ctx: &mut UninstantiableWrapper<P>,
        _cb: F,
    ) -> O {
        core_ctx.uninstantiable_unreachable()
    }

    fn with_other_bound_sockets_mut<
        O,
        F: FnOnce(
            &mut Self::IpSocketsCtx<'_>,
            &mut BoundSockets<
                I::OtherVersion,
                P::WeakDeviceId,
                S::AddrSpec,
                S::SocketMapSpec<<I>::OtherVersion, P::WeakDeviceId>,
            >,
        ) -> O,
    >(
        core_ctx: &mut UninstantiableWrapper<P>,
        _cb: F,
    ) -> O {
        core_ctx.uninstantiable_unreachable()
    }

    fn with_transport_context<O, F: FnOnce(&mut Self::IpSocketsCtx<'_>) -> O>(
        core_ctx: &mut UninstantiableWrapper<P>,
        _cb: F,
    ) -> O {
        core_ctx.uninstantiable_unreachable()
    }
}