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 <https/RunLoop.h> 20 21 #include <memory> 22 #include <optional> 23 #include <string_view> 24 25 #include <netinet/in.h> 26 #include <openssl/ssl.h> 27 28 struct RTPSession : std::enable_shared_from_this<RTPSession> { 29 explicit RTPSession( 30 std::string_view localUFrag, 31 std::string_view localPassword, 32 std::shared_ptr<X509> localCertificate, 33 std::shared_ptr<EVP_PKEY> localKey); 34 35 bool isActive() const; 36 void setIsActive(); 37 38 void setRemoteParams( 39 std::string_view remoteUFrag, 40 std::string_view remotePassword, 41 std::string_view remoteFingerprint); 42 43 std::string localUFrag() const; 44 std::string localPassword() const; 45 std::shared_ptr<X509> localCertificate() const; 46 std::shared_ptr<EVP_PKEY> localKey() const; 47 std::string localFingerprint() const; 48 49 std::string remoteUFrag() const; 50 std::string remotePassword() const; 51 std::string remoteFingerprint() const; 52 53 bool hasRemoteAddress() const; 54 sockaddr_storage remoteAddress() const; 55 void setRemoteAddress(const sockaddr_storage &remoteAddr); 56 57 void schedulePing( 58 std::shared_ptr<RunLoop> runLoop, 59 RunLoop::AsyncFunction cb, 60 std::chrono::steady_clock::duration delay); 61 62 private: 63 std::string mLocalUFrag; 64 std::string mLocalPassword; 65 std::shared_ptr<X509> mLocalCertificate; 66 std::shared_ptr<EVP_PKEY> mLocalKey; 67 68 std::optional<std::string> mRemoteUFrag; 69 std::optional<std::string> mRemotePassword; 70 std::optional<std::string> mRemoteFingerprint; 71 std::optional<sockaddr_storage> mRemoteAddr; 72 73 RunLoop::Token mPingToken; 74 75 bool mIsActive; 76 }; 77