-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cc
149 lines (126 loc) · 3.96 KB
/
main.cc
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
#include <fcntl.h>
#include <filesystem>
#include <openssl/http.h>
#include <fstream>
#include <iostream>
#include <fmt/format.h>
#include <spdlog/common.h>
#include <thread>
#include "common.h"
#include "database.h"
#include "server.h"
#include "utils.h"
#include "workers/BubbleFetcher.h"
Config default_config = {
.domain = "your.domain",
.sockethost = "0.0.0.0",
.socketport = 2001,
.instanceactor = "test3",
.mediapath = "media",
.bubbledHosts = {"wetdry.world"}
};
Config cfg;
json context;
#define LOCK_FILE "/tmp/cabin.lock"
void registeruser();
int main(int argc, char **argv) {
spdlog::set_level(spdlog::level::trace);
spdlog::set_pattern("[%M:%S] [%^%L%$] [%&] %v");
int lockFile = open(LOCK_FILE, O_CREAT | O_RDWR, 0666);
if (lockFile < 0) {
std::cerr << "Error: Unable to open lock file." << std::endl;
exit(EXIT_FAILURE);
}
if (lockf(lockFile, F_TLOCK, 0) < 0) {
std::cerr << "Error: Unable to lock file." << std::endl;
exit(EXIT_FAILURE);
}
string config_path = "config.json";
std::ifstream s(config_path);
if (!s) {
std::ofstream s(config_path, std::ios::app);
if (!s) {
std::cout << "can't read config" << "\n";
}
json j = default_config;
s << j.dump();
s.close();
std::cout << "No config file found, wrote one for you";
exit(1);
}
json j = json::parse(std::string((std::istreambuf_iterator<char>(s)), std::istreambuf_iterator<char>()));
cfg = j.template get<Config>();
std::ifstream contextst("context.json");
context = json::parse(std::string((std::istreambuf_iterator<char>(contextst)), std::istreambuf_iterator<char>()));
if (!std::filesystem::exists(cfg.mediapath)) {
std::filesystem::create_directories(cfg.mediapath);
}
info("loaded ({})", cfg.domain);
Database::Init();
BubbleFetcher::Launch();
std::thread s1([](){
// NoteService::fetchRemote("https://brain.worm.pink/objects/1944398f-007c-42e6-8dfd-efcada1500a8");
});
Server::Listen();
s1.join();
// if (argc > 1) {
// URL url(argv[1]);
// dbg(argv[1]);
// auto u = UserService::lookup(ct->userid);
// APClient cli(*u, url.host);
// auto c = cli.Get(url.path);
//
// if (c->status == 200) {
// dbg(c->body);
// std::cout << json::parse(c->body).dump(2);
// } else {
// error("{} : ({})", c->status, c->body);
// }
//
// exit(0);
// }
//
// auto u = UserService::lookup(ct->userid);
// json j = {
// {"@context", "https://www.w3.org/ns/activitystreams"},
// {"id", API("relayfollows/0")},
// {"type", "Follow"},
// {"actor", USERPAGE(ct->userid)},
// {"object", "https://www.w3.org/ns/activitystreams#Public"}
// };
// APClient cli(u.value(), "relay.toot.io");
// auto c = cli.Post("/inbox", j);
// error("{} : ({})", c->status, c->body);
// json j = {
// {"id", API("follows/0")},
// {"type", "Follow"},
// {"actor", USERPAGE(ct->userid)},
// {"object", "https://booping.synth.download/users/a005c9wl4pwj0arp"}
// };
// APClient cli(u.value(), "booping.synth.download");
// auto c = cli.Post("/inbox", j);
// error("{} : ({})", c->status, c->body);
// json j = {
// {"id", API("bites/0")},
// {"type", "Bite"},
// {"actor", USERPAGE(ct->userid)},
// {"target", "https://is.notfire.cc/users/9yr98tgk15rj9zaw"},
// {"to", "https://is.notfire.cc/users/9yr98tgk15rj9zaw"},
// {"published", utils::dateISO()},
// };
// APClient cli(u.value(), "is.notfire.cc");
// auto c = cli.Post("/inbox", j);
// error("{} : ({})", c->status, c->body);
// json j = {
// {"id", API("bites/0")},
// {"type", "Bite"},
// {"actor", USERPAGE(ct->userid)},
// {"target", "https://is.notfire.cc/users/9yr98tgk15rj9zaw"},
// {"to", "https://is.notfire.cc/users/9yr98tgk15rj9zaw"},
// {"published", utils::dateISO()},
// };
// APClient cli(u.value(), "is.notfire.cc");
// auto c = cli.Post("/inbox", j);
// error("{} : ({})", c->status, c->body);
return 0;
}