Ring Daemon 16.0.0
Loading...
Searching...
No Matches
gittransport.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2004-2025 Savoir-faire Linux Inc.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17#pragma once
18
19#include <memory>
20#include <string>
21#include <string_view>
22#include <algorithm>
23#include <git2/remote.h>
24#include <git2/sys/transport.h>
25#include <git2/errors.h>
26#include <git2.h>
27
28namespace jami {
29class Manager;
30} // namespace jami
31
32namespace dhtnet {
33class ChannelSocket;
34} // namespace dhtnet
35
36// NOTE: THIS MUST BE IN THE ROOT NAMESPACE FOR LIBGIT2
37
39{
40 git_smart_subtransport_stream base;
41 std::weak_ptr<dhtnet::ChannelSocket> socket;
42
43 std::string cmd {};
44 std::string url {};
45 unsigned sent_command : 1;
46};
47
49{
50 git_smart_subtransport base;
51 std::unique_ptr<P2PStream> stream;
52 git_remote* remote;
53};
54
55using namespace std::string_view_literals;
56constexpr auto UPLOAD_PACK_CMD = "git-upload-pack"sv;
57constexpr auto HOST_TAG = "host="sv;
58
59/*
60 * Create a git protocol request.
61 *
62 * For example: 0029git-upload-pack conversation\0host=device\0
63 * @param buf The buffer to fill
64 * @param cmd The wanted command
65 * @param url The repository's URL
66 * @return 0 on success, - 1 on error
67 */
68int generateRequest(git_buf* request, const std::string& cmd, const std::string_view& url);
69
75int sendCmd(P2PStream* s);
76
85int P2PStreamRead(git_smart_subtransport_stream* stream, char* buffer, size_t buflen, size_t* read);
86
87int P2PStreamWrite(git_smart_subtransport_stream* stream, const char* buffer, size_t len);
88
92void P2PStreamFree(git_smart_subtransport_stream* stream);
93
102int P2PSubTransportAction(git_smart_subtransport_stream** out,
103 git_smart_subtransport* transport,
104 const char* url,
105 git_smart_service_t action);
106
112int P2PSubTransportClose(git_smart_subtransport*);
113
118void P2PSubTransportFree(git_smart_subtransport* transport);
119
127int P2PSubTransportNew(P2PSubTransport** out, git_transport* owner, void* payload);
128
136int p2p_subtransport_cb(git_smart_subtransport** out, git_transport* owner, void* payload);
137
144int p2p_transport_cb(git_transport** out, git_remote* owner, void* param);
int P2PStreamRead(git_smart_subtransport_stream *stream, char *buffer, size_t buflen, size_t *read)
Read on a channel socket.
int P2PStreamWrite(git_smart_subtransport_stream *stream, const char *buffer, size_t len)
int P2PSubTransportClose(git_smart_subtransport *)
Close a subtransport Because we use a channel socket, we need to do nothing here.
int generateRequest(git_buf *request, const std::string &cmd, const std::string_view &url)
constexpr auto UPLOAD_PACK_CMD
int P2PSubTransportAction(git_smart_subtransport_stream **out, git_smart_subtransport *transport, const char *url, git_smart_service_t action)
Handles git actions.
int p2p_subtransport_cb(git_smart_subtransport **out, git_transport *owner, void *payload)
Setup the subtransport callback.
void P2PStreamFree(git_smart_subtransport_stream *stream)
Free resources used by the stream.
int P2PSubTransportNew(P2PSubTransport **out, git_transport *owner, void *payload)
Create a new subtransport.
int sendCmd(P2PStream *s)
Send a git command on the linked socket.
constexpr auto HOST_TAG
void P2PSubTransportFree(git_smart_subtransport *transport)
Free resources used by a transport.
int p2p_transport_cb(git_transport **out, git_remote *owner, void *param)
Setup the transport callback.
std::string cmd
unsigned sent_command
std::weak_ptr< dhtnet::ChannelSocket > socket
std::string url
git_smart_subtransport_stream base
std::unique_ptr< P2PStream > stream
git_smart_subtransport base
git_remote * remote