• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <webrtc/DTLS.h>
20 
21 #include <https/RunLoop.h>
22 
23 #include <memory>
24 
25 struct SCTPHandler : public std::enable_shared_from_this<SCTPHandler> {
26     explicit SCTPHandler(
27             std::shared_ptr<RunLoop> runLoop,
28             std::shared_ptr<DTLS> dtls);
29 
30     void run();
31 
32     int inject(uint8_t *data, size_t size);
33 
34 private:
35     std::shared_ptr<RunLoop> mRunLoop;
36     std::shared_ptr<DTLS> mDTLS;
37 
38     uint32_t mInitiateTag;
39     uint32_t mSendingTSN;
40     bool mSentGreeting;
41 
42     int processChunk(
43             uint16_t srcPort,
44             const uint8_t *data,
45             size_t size,
46             bool firstChunk,
47             bool lastChunk);
48 
49     static uint32_t crc32c(const uint8_t *data, size_t size);
50 
51     void onSendGreeting(uint16_t srcPort, size_t index);
52 };
53