simplify references to server_name
Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
parent
71a3855af6
commit
3e0ff2dc84
13 changed files with 29 additions and 26 deletions
|
@ -554,7 +554,7 @@ pub(super) async fn first_pdu_in_room(
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_in_room(&self.services.server.config.server_name, &room_id)
|
.server_in_room(&self.services.server.name, &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Ok(RoomMessageEventContent::text_plain(
|
return Ok(RoomMessageEventContent::text_plain(
|
||||||
|
@ -583,7 +583,7 @@ pub(super) async fn latest_pdu_in_room(
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_in_room(&self.services.server.config.server_name, &room_id)
|
.server_in_room(&self.services.server.name, &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Ok(RoomMessageEventContent::text_plain(
|
return Ok(RoomMessageEventContent::text_plain(
|
||||||
|
@ -613,7 +613,7 @@ pub(super) async fn force_set_room_state_from_server(
|
||||||
.services
|
.services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_in_room(&self.services.server.config.server_name, &room_id)
|
.server_in_room(&self.services.server.name, &room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Ok(RoomMessageEventContent::text_plain(
|
return Ok(RoomMessageEventContent::text_plain(
|
||||||
|
@ -757,7 +757,7 @@ pub(super) async fn get_signing_keys(
|
||||||
query: bool,
|
query: bool,
|
||||||
) -> Result<RoomMessageEventContent> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
let server_name =
|
let server_name =
|
||||||
server_name.unwrap_or_else(|| self.services.server.config.server_name.clone().into());
|
server_name.unwrap_or_else(|| self.services.server.name.clone().into());
|
||||||
|
|
||||||
if let Some(notary) = notary {
|
if let Some(notary) = notary {
|
||||||
let signing_keys = self
|
let signing_keys = self
|
||||||
|
@ -794,7 +794,7 @@ pub(super) async fn get_verify_keys(
|
||||||
server_name: Option<Box<ServerName>>,
|
server_name: Option<Box<ServerName>>,
|
||||||
) -> Result<RoomMessageEventContent> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
let server_name =
|
let server_name =
|
||||||
server_name.unwrap_or_else(|| self.services.server.config.server_name.clone().into());
|
server_name.unwrap_or_else(|| self.services.server.name.clone().into());
|
||||||
|
|
||||||
let keys = self
|
let keys = self
|
||||||
.services
|
.services
|
||||||
|
@ -824,7 +824,7 @@ pub(super) async fn resolve_true_destination(
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
if server_name == self.services.server.config.server_name {
|
if server_name == self.services.server.name {
|
||||||
return Ok(RoomMessageEventContent::text_plain(
|
return Ok(RoomMessageEventContent::text_plain(
|
||||||
"Not allowed to send federation requests to ourselves. Please use `get-pdu` for \
|
"Not allowed to send federation requests to ourselves. Please use `get-pdu` for \
|
||||||
fetching local PDUs.",
|
fetching local PDUs.",
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub(super) async fn remote_user_in_rooms(
|
||||||
&self,
|
&self,
|
||||||
user_id: Box<UserId>,
|
user_id: Box<UserId>,
|
||||||
) -> Result<RoomMessageEventContent> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
if user_id.server_name() == self.services.server.config.server_name {
|
if user_id.server_name() == self.services.server.name {
|
||||||
return Ok(RoomMessageEventContent::text_plain(
|
return Ok(RoomMessageEventContent::text_plain(
|
||||||
"User belongs to our server, please use `list-joined-rooms` user admin command \
|
"User belongs to our server, please use `list-joined-rooms` user admin command \
|
||||||
instead.",
|
instead.",
|
||||||
|
|
|
@ -34,7 +34,7 @@ pub(super) async fn reload_config(
|
||||||
) -> Result<RoomMessageEventContent> {
|
) -> Result<RoomMessageEventContent> {
|
||||||
let path = path.as_deref().into_iter();
|
let path = path.as_deref().into_iter();
|
||||||
let config = Config::load(path).and_then(|raw| Config::new(&raw))?;
|
let config = Config::load(path).and_then(|raw| Config::new(&raw))?;
|
||||||
if config.server_name != self.services.server.config.server_name {
|
if config.server_name != self.services.server.name {
|
||||||
return Err!("You can't change the server name.");
|
return Err!("You can't change the server name.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ pub(crate) async fn create_openid_token_route(
|
||||||
Ok(account::request_openid_token::v3::Response {
|
Ok(account::request_openid_token::v3::Response {
|
||||||
access_token,
|
access_token,
|
||||||
token_type: TokenType::Bearer,
|
token_type: TokenType::Bearer,
|
||||||
matrix_server_name: services.server.config.server_name.clone(),
|
matrix_server_name: services.server.name.clone(),
|
||||||
expires_in: Duration::from_secs(expires_in),
|
expires_in: Duration::from_secs(expires_in),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,7 +50,7 @@ pub(crate) async fn report_room_route(
|
||||||
if !services
|
if !services
|
||||||
.rooms
|
.rooms
|
||||||
.state_cache
|
.state_cache
|
||||||
.server_in_room(&services.server.config.server_name, &body.room_id)
|
.server_in_room(&services.server.name, &body.room_id)
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
return Err!(Request(NotFound(
|
return Err!(Request(NotFound(
|
||||||
|
|
|
@ -71,7 +71,7 @@ pub(crate) async fn create_room_route(
|
||||||
let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id {
|
let room_id: OwnedRoomId = if let Some(custom_room_id) = &body.room_id {
|
||||||
custom_room_id_check(&services, custom_room_id)?
|
custom_room_id_check(&services, custom_room_id)?
|
||||||
} else {
|
} else {
|
||||||
RoomId::new(&services.server.config.server_name)
|
RoomId::new(&services.server.name)
|
||||||
};
|
};
|
||||||
|
|
||||||
// check if room ID doesn't already exist instead of erroring on auth check
|
// check if room ID doesn't already exist instead of erroring on auth check
|
||||||
|
|
|
@ -38,7 +38,7 @@ pub(crate) async fn turn_server_route(
|
||||||
let user = body.sender_user.unwrap_or_else(|| {
|
let user = body.sender_user.unwrap_or_else(|| {
|
||||||
UserId::parse_with_server_name(
|
UserId::parse_with_server_name(
|
||||||
utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(),
|
utils::random_string(RANDOM_USER_ID_LENGTH).to_lowercase(),
|
||||||
&services.server.config.server_name,
|
&services.server.name,
|
||||||
)
|
)
|
||||||
.unwrap()
|
.unwrap()
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,12 +6,17 @@ use std::{
|
||||||
time::SystemTime,
|
time::SystemTime,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use ruma::OwnedServerName;
|
||||||
use tokio::{runtime, sync::broadcast};
|
use tokio::{runtime, sync::broadcast};
|
||||||
|
|
||||||
use crate::{config, config::Config, err, log::Log, metrics::Metrics, Err, Result};
|
use crate::{config, config::Config, err, log::Log, metrics::Metrics, Err, Result};
|
||||||
|
|
||||||
/// Server runtime state; public portion
|
/// Server runtime state; public portion
|
||||||
pub struct Server {
|
pub struct Server {
|
||||||
|
/// Configured name of server. This is the same as the one in the config
|
||||||
|
/// but developers can (and should) reference this string instead.
|
||||||
|
pub name: OwnedServerName,
|
||||||
|
|
||||||
/// Server-wide configuration instance
|
/// Server-wide configuration instance
|
||||||
pub config: config::Manager,
|
pub config: config::Manager,
|
||||||
|
|
||||||
|
@ -46,6 +51,7 @@ impl Server {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
|
pub fn new(config: Config, runtime: Option<runtime::Handle>, log: Log) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
name: config.server_name.clone(),
|
||||||
config: config::Manager::new(config),
|
config: config::Manager::new(config),
|
||||||
started: SystemTime::now(),
|
started: SystemTime::now(),
|
||||||
stopping: AtomicBool::new(false),
|
stopping: AtomicBool::new(false),
|
||||||
|
|
|
@ -61,11 +61,11 @@ impl crate::Service for Service {
|
||||||
db,
|
db,
|
||||||
server: args.server.clone(),
|
server: args.server.clone(),
|
||||||
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
bad_event_ratelimiter: Arc::new(RwLock::new(HashMap::new())),
|
||||||
admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &config.server_name))
|
admin_alias: OwnedRoomAliasId::try_from(format!("#admins:{}", &args.server.name))
|
||||||
.expect("#admins:server_name is valid alias name"),
|
.expect("#admins:server_name is valid alias name"),
|
||||||
server_user: UserId::parse_with_server_name(
|
server_user: UserId::parse_with_server_name(
|
||||||
String::from("conduit"),
|
String::from("conduit"),
|
||||||
&config.server_name,
|
&args.server.name,
|
||||||
)
|
)
|
||||||
.expect("@conduit:server_name is valid"),
|
.expect("@conduit:server_name is valid"),
|
||||||
turn_secret,
|
turn_secret,
|
||||||
|
@ -107,7 +107,7 @@ impl Service {
|
||||||
pub fn current_count(&self) -> Result<u64> { Ok(self.db.current_count()) }
|
pub fn current_count(&self) -> Result<u64> { Ok(self.db.current_count()) }
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn server_name(&self) -> &ServerName { self.server.config.server_name.as_ref() }
|
pub fn server_name(&self) -> &ServerName { self.server.name.as_ref() }
|
||||||
|
|
||||||
pub fn allow_registration(&self) -> bool { self.server.config.allow_registration }
|
pub fn allow_registration(&self) -> bool { self.server.config.allow_registration }
|
||||||
|
|
||||||
|
@ -207,7 +207,7 @@ impl Service {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn server_is_ours(&self, server_name: &ServerName) -> bool {
|
pub fn server_is_ours(&self, server_name: &ServerName) -> bool {
|
||||||
server_name == self.server.config.server_name
|
server_name == self.server_name()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -218,8 +218,6 @@ async fn migrate(services: &Services) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn db_lt_12(services: &Services) -> Result<()> {
|
async fn db_lt_12(services: &Services) -> Result<()> {
|
||||||
let config = &services.server.config;
|
|
||||||
|
|
||||||
for username in &services
|
for username in &services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
|
@ -227,7 +225,8 @@ async fn db_lt_12(services: &Services) -> Result<()> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
let user = match UserId::parse_with_server_name(username.as_str(), &config.server_name) {
|
let user = match UserId::parse_with_server_name(username.as_str(), &services.server.name)
|
||||||
|
{
|
||||||
| Ok(u) => u,
|
| Ok(u) => u,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
warn!("Invalid username {username}: {e}");
|
warn!("Invalid username {username}: {e}");
|
||||||
|
@ -297,8 +296,6 @@ async fn db_lt_12(services: &Services) -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn db_lt_13(services: &Services) -> Result<()> {
|
async fn db_lt_13(services: &Services) -> Result<()> {
|
||||||
let config = &services.server.config;
|
|
||||||
|
|
||||||
for username in &services
|
for username in &services
|
||||||
.users
|
.users
|
||||||
.list_local_users()
|
.list_local_users()
|
||||||
|
@ -306,7 +303,8 @@ async fn db_lt_13(services: &Services) -> Result<()> {
|
||||||
.collect::<Vec<_>>()
|
.collect::<Vec<_>>()
|
||||||
.await
|
.await
|
||||||
{
|
{
|
||||||
let user = match UserId::parse_with_server_name(username.as_str(), &config.server_name) {
|
let user = match UserId::parse_with_server_name(username.as_str(), &services.server.name)
|
||||||
|
{
|
||||||
| Ok(u) => u,
|
| Ok(u) => u,
|
||||||
| Err(e) => {
|
| Err(e) => {
|
||||||
warn!("Invalid username {username}: {e}");
|
warn!("Invalid username {username}: {e}");
|
||||||
|
|
|
@ -401,8 +401,7 @@ impl super::Service {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn validate_dest(&self, dest: &ServerName) -> Result<()> {
|
fn validate_dest(&self, dest: &ServerName) -> Result<()> {
|
||||||
let config = &self.services.server.config;
|
if dest == self.services.server.name && !self.services.server.config.federation_loopback {
|
||||||
if dest == config.server_name && !config.federation_loopback {
|
|
||||||
return Err!("Won't send federation request to ourselves");
|
return Err!("Won't send federation request to ourselves");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -150,7 +150,7 @@ impl Service {
|
||||||
let servers_contains_ours = || {
|
let servers_contains_ours = || {
|
||||||
servers
|
servers
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.is_some_and(|servers| servers.contains(&self.services.server.config.server_name))
|
.is_some_and(|servers| servers.contains(&self.services.server.name))
|
||||||
};
|
};
|
||||||
|
|
||||||
if !server_is_ours && !servers_contains_ours() {
|
if !server_is_ours && !servers_contains_ours() {
|
||||||
|
|
|
@ -850,7 +850,7 @@ impl Service {
|
||||||
let txn_id = &*general_purpose::URL_SAFE_NO_PAD.encode(txn_hash);
|
let txn_id = &*general_purpose::URL_SAFE_NO_PAD.encode(txn_hash);
|
||||||
|
|
||||||
let request = send_transaction_message::v1::Request {
|
let request = send_transaction_message::v1::Request {
|
||||||
origin: self.server.config.server_name.clone(),
|
origin: self.server.name.clone(),
|
||||||
pdus: pdu_jsons,
|
pdus: pdu_jsons,
|
||||||
edus: edu_jsons,
|
edus: edu_jsons,
|
||||||
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
origin_server_ts: MilliSecondsSinceUnixEpoch::now(),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue