Documentation
¶
Index ¶
- Constants
- Variables
- func AuthorKeyToPeerID(authorKeyHex string) (peer.ID, error)
- func FounderBanPayload(bannedPeer, reason string, expiresAt time.Time, permanent bool, ...) []byte
- func FounderUnbanPayload(bannedPeer string, issuedAt time.Time) []byte
- func IssueBanFor(ctx context.Context, mod *Moderator, topic *network.Topic, ...) error
- func IssueUnbanFor(ctx context.Context, mod *Moderator, topic *network.Topic, ...) error
- func LoadFounderKey(dataDir, myPubKeyHex string) (isFounder bool, err error)
- func ModeratorBanPayload(bannedPeer, reason string, expiresAt time.Time, permanent bool, ...) []byte
- func ModeratorCertPayload(targetKeyHex string, issuedAt, expiresAt time.Time, permanent bool) []byte
- func ModeratorUnbanPayload(bannedPeer string, issuedAt time.Time) []byte
- func PeerIDToAuthorKey(pid peer.ID) (string, error)
- type BanEntry
- type BanInfo
- type BanMsg
- type Envelope
- type GrantedMod
- type HistoryAction
- type HistoryEntry
- type Moderator
- func (m *Moderator) AllBans() []BanEntry
- func (m *Moderator) AuthorBanInfo(authorKeyHex string) (info BanInfo, ok bool)
- func (m *Moderator) FindOwnCert(pubHex string) *ModeratorCert
- func (m *Moderator) GrantedMods() []GrantedMod
- func (m *Moderator) History() []HistoryEntry
- func (m *Moderator) InterceptAccept(_ lp2pnet.ConnMultiaddrs) bool
- func (m *Moderator) InterceptAddrDial(pid peer.ID, _ ma.Multiaddr) bool
- func (m *Moderator) InterceptPeerDial(pid peer.ID) bool
- func (m *Moderator) InterceptSecured(_ lp2pnet.Direction, pid peer.ID, _ lp2pnet.ConnMultiaddrs) bool
- func (m *Moderator) InterceptUpgraded(_ lp2pnet.Conn) (bool, control.DisconnectReason)
- func (m *Moderator) IsAuthorBanned(authorKeyHex string) bool
- func (m *Moderator) IsBanned(pid peer.ID) bool
- func (m *Moderator) IssueBan(ctx context.Context, topic *network.Topic, ban BanMsg) error
- func (m *Moderator) IssueGrant(founderPriv ed25519.PrivateKey, targetKeyHex string, expiresAt time.Time, ...) (cert ModeratorCert, certPath string, err error)
- func (m *Moderator) IssueRevoke(ctx context.Context, topic *network.Topic, rev RevokeMsg) error
- func (m *Moderator) IssueUnban(ctx context.Context, topic *network.Topic, u UnbanMsg) error
- func (m *Moderator) PeerBanInfo(pid peer.ID) (info BanInfo, ok bool)
- func (m *Moderator) PublishBan(ctx context.Context, topic *network.Topic, ban BanMsg) error
- func (m *Moderator) PublishRevoke(ctx context.Context, topic *network.Topic, rev RevokeMsg) error
- func (m *Moderator) PublishSavedBans(ctx context.Context, topic *network.Topic, dataDir string)
- func (m *Moderator) PublishUnban(ctx context.Context, topic *network.Topic, u UnbanMsg) error
- func (m *Moderator) Start(ctx context.Context, topic *network.Topic)
- func (m *Moderator) Stop()
- func (m *Moderator) VerifyFounderSignature(payload, sig []byte) bool
- func (m *Moderator) VerifyModeratorCert(cert ModeratorCert) bool
- type ModeratorCert
- type PersistedBan
- type RevokeMsg
- type UnbanMsg
Constants ¶
const FounderKeyFile = "founder.key"
const MaxCertDays = maxCertDays
MaxCertDays, verifyCert'in kabul ettiği (kalıcı olmayan) bir sertifikanın en uzun geçerlilik süresidir (gün).
const ModerationTopic = protokol.ModerasyonKonusu
Variables ¶
var FounderPubKeyHex = defaultFounderPubKeyHex
Functions ¶
func AuthorKeyToPeerID ¶
AuthorKeyToPeerID, forum/chat/DM AuthorKey'i olarak kullanılan hex-encoded ed25519 public key'i, aynı anahtarın libp2p ağ kimliği (peer.ID) karşılığına çevirir.
AND'de her düğüm TEK bir ed25519 anahtar çifti kullanır: bu anahtar hem libp2p Peer ID'sini (bkz. internal/network.libp2pPrivateKey) hem de forum/chat/DM imzalarındaki AuthorKey'i (bkz. internal/crypto.Identity) üretir. Yani bir AuthorKey'den, o yazarın gerçek ağ kimliğine (peer.ID) geri dönmek mümkündür — bu da bir moderatör banının (peer.ID bazlı) aynı kişinin forum/chat içeriğine karşı da uygulanabilmesini sağlar (bkz. IsAuthorBanned).
func FounderBanPayload ¶
func FounderBanPayload(bannedPeer, reason string, expiresAt time.Time, permanent bool, issuedAt time.Time) []byte
FounderBanPayload deterministically encodes what a founder-issued BanMsg's Sig must cover — shared by verifyFounderBan and SignFounderBan. The "founder|" prefix keeps this byte-distinct from ModeratorBanPayload's format (same BannedPeer/Reason/ExpiresAt could otherwise coincide), so a signature valid for one can never be replayed as the other.
func FounderUnbanPayload ¶
FounderUnbanPayload deterministically encodes what a founder-issued UnbanMsg's Sig must cover — shared by verifyFounderUnban and SignFounderUnban. The "founder-unban|" prefix keeps this byte-distinct from ModeratorUnbanPayload's format (and from every other payload kind in this file), so a signature valid for one can never be replayed as another.
func IssueBanFor ¶
func IssueBanFor(ctx context.Context, mod *Moderator, topic *network.Topic, signerPriv ed25519.PrivateKey, targetAuthorKey string, isFounder bool, cert *ModeratorCert, reason string, expiresAt time.Time, permanent bool) error
IssueBanFor builds and issues a ban for targetAuthorKey signed by signerPriv — either as founder (cert==nil) or as a moderator (cert!=nil). Shared by the TUI's profile-screen ban action and the admin plugin's moderation backend (bkz. cmd/and'in modAdapter'ı) so both sign/apply/ publish identically instead of duplicating this orchestration twice.
func IssueUnbanFor ¶
func IssueUnbanFor(ctx context.Context, mod *Moderator, topic *network.Topic, signerPriv ed25519.PrivateKey, targetAuthorKey string, isFounder bool, cert *ModeratorCert) error
IssueUnbanFor lifts an active ban on targetAuthorKey, signed by signerPriv — either as founder (cert==nil) or as a moderator (cert!=nil). Uses the same authority as banning: any identity that could ban a target can also unban them. Shared by the TUI's profile-screen unban action and the admin plugin's moderation backend.
func LoadFounderKey ¶
LoadFounderKey, dataDir/founder.key dosyasını okuyup FounderPubKeyHex'i buna göre ayarlar ve bu düğümün kurucu olup olmadığını döner.
founder.key henüz yoksa iki durum vardır:
- Binary -ldflags "-X .../FounderPubKeyHex=<hex>" ile GERÇEK bir kurucu anahtarıyla derlendiyse (FounderPubKeyHex artık defaultFounderPubKeyHex DEĞİLSE), bu değer OTORİTERDİR ve dosyaya AYNEN yazılır — myPubKeyHex yalnızca bununla karşılaştırılıp isFounder'ı belirlemek için kullanılır. Aksi davranış (myPubKeyHex'i doğrudan dosyaya yazmak), derleme zamanında gömülü gerçek kurucu anahtarını YOK SAYAR ve ilk çalıştıran HERKESİ kendi kurucusu ilan eder — moderasyonun tüm güven zincirini kırar (gerçek kurucunun ban/moderatör mesajları artık hiç kabul edilmez, çünkü karşılaştırılan anahtar artık o kullanıcının kendi anahtarıdır).
- Hiçbir kurucu anahtarı gömülmediyse (geliştirme/tekli-düğüm testi), bu düğüm kendi kimliğini kurucu olarak başlatır (eski davranış).
os.O_EXCL ile atomik oluşturma, aynı veri dizinini paylaşan iki sürecin aynı anda ilk kez başlamasında birinin yazdığı değerin diğerince sessizce ezilmesini önler — yarışı kaybeden taraf dosyayı yeniden okur.
func ModeratorBanPayload ¶
func ModeratorBanPayload(bannedPeer, reason string, expiresAt time.Time, permanent bool, issuedAt time.Time) []byte
ModeratorBanPayload deterministically encodes what a moderator-issued BanMsg's Sig must cover — shared by verifyBan and SignModeratorBan (the TUI and andmod both call the latter) so signer and verifier can never drift apart.
func ModeratorCertPayload ¶
func ModeratorCertPayload(targetKeyHex string, issuedAt, expiresAt time.Time, permanent bool) []byte
ModeratorCertPayload deterministically encodes what a ModeratorCert's Sig must cover — shared by verifyCert, FindModCert and SignModeratorCert so signer and every verifier can never drift apart. issuedAt is included so the holder of a cert can't rewrite it to dodge a revoke.
func ModeratorUnbanPayload ¶
ModeratorUnbanPayload deterministically encodes what a moderator-issued UnbanMsg's Sig must cover — shared by verifyUnban and SignModeratorUnban.
Types ¶
type BanEntry ¶
type BanEntry struct {
PeerID string
AuthorKey string // PeerIDToAuthorKey başarısız olursa boş
ExpiresAt time.Time
Permanent bool
ModeratorKey string
Reason string
}
BanEntry is one row of AllBans' snapshot — a currently-active ban with enough detail (target, remaining time, issuer, reason) to render the Ban Listesi screen without a second lookup.
type BanInfo ¶
type BanInfo struct {
ExpiresAt time.Time // Permanent ise sıfır değer, kullanılmaz
Permanent bool
ModeratorKey string
Reason string
}
BanInfo reports the details of one active ban — used to show ban status (kalan süre/ömür boyu/sebep) on a profile screen, as opposed to IsBanned/IsAuthorBanned's plain yes/no.
type BanMsg ¶
type BanMsg struct {
BannedPeer string `json:"banned_peer"`
Reason string `json:"reason"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Permanent bool `json:"permanent,omitempty"`
Cert ModeratorCert `json:"cert"`
// IssuedAt, bu banın imzalandığı andır — bkz. Moderator.unbannedSince'in
// doc yorumu: bunsuz, süresi dolmadan geri alınmış (unban edilmiş) bir
// banın ESKİ dosyası (ör. bans/ban_<peer>.json), banı VEREN moderatörün
// kendi düğümü yeniden başladığında (PublishSavedBans ile) yeniden
// yayınlanır ve gerçek unban'ı görmemiş her düğümde sessizce yeniden
// uygulanırdı — alreadySeen yalnızca BELLEK İÇİ bir tekrar önleme
// önbelleğidir, yeniden başlatmada sıfırlanır, bu yüzden tek başına
// yeterli değildir.
IssuedAt time.Time `json:"issued_at,omitempty"`
Sig string `json:"sig"`
}
func SignFounderBan ¶
func SignFounderBan(founderPriv ed25519.PrivateKey, bannedPeer, reason string, expiresAt time.Time, permanent bool) BanMsg
SignFounderBan builds a BanMsg signed directly by the founder's own key (founderPriv), with no ModeratorCert attached — see applyBan's doc comment for why the founder needs this separate path.
func SignModeratorBan ¶
func SignModeratorBan(modPriv ed25519.PrivateKey, cert ModeratorCert, bannedPeer, reason string, expiresAt time.Time, permanent bool) BanMsg
SignModeratorBan builds a BanMsg signed by a moderator's own key (modPriv) using their granted cert — the shared reference implementation for both andmod's CLI and the TUI's in-app ban action. cert must belong to the same key as modPriv (cert.ModeratorKey == hex(modPriv's public key)); callers are responsible for that match (see FindModCert, which only ever returns certs for the key you ask it for).
type GrantedMod ¶
type GrantedMod struct {
Key string `json:"key"`
GrantedAt time.Time `json:"granted_at"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Permanent bool `json:"permanent,omitempty"`
Revoked bool `json:"revoked,omitempty"`
RevokedAt time.Time `json:"revoked_at,omitempty"`
}
GrantedMod is one row of this node's local record of moderator certificates IT (as founder) has issued via IssueGrant.
type HistoryAction ¶
type HistoryAction string
HistoryAction identifies which kind of moderation event a HistoryEntry records.
const ( HistoryBan HistoryAction = "ban" HistoryUnban HistoryAction = "unban" )
type HistoryEntry ¶
type HistoryEntry struct {
Action HistoryAction `json:"action"`
PeerID string `json:"peer_id"`
Reason string `json:"reason,omitempty"`
ModeratorKey string `json:"moderator_key"`
At time.Time `json:"at"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Permanent bool `json:"permanent,omitempty"`
}
HistoryEntry is one row of this node's local moderation audit log — unlike m.bans (current state only), history never removes entries.
type Moderator ¶
type Moderator struct {
// contains filtered or unexported fields
}
func (*Moderator) AllBans ¶
AllBans returns a snapshot of every currently-active ban (permanent, or temporary and not yet expired), sorted by PeerID for a stable render order across calls. Powers the Ban Listesi screen.
func (*Moderator) AuthorBanInfo ¶
AuthorBanInfo is PeerBanInfo for an AuthorKey — see AuthorKeyToPeerID's doc comment for why forum/chat AuthorKeys and peer.IDs are the same underlying identity in AND.
func (*Moderator) FindOwnCert ¶
func (m *Moderator) FindOwnCert(pubHex string) *ModeratorCert
FindOwnCert is a convenience wrapper around FindModCert using this Moderator's own dataDir, so callers that already hold a *Moderator (e.g. profile.Store) don't need to separately thread a dataDir through just to look up a cert for a given pubkey.
func (*Moderator) GrantedMods ¶
func (m *Moderator) GrantedMods() []GrantedMod
GrantedMods returns a copy of this node's local grant record, newest first.
func (*Moderator) History ¶
func (m *Moderator) History() []HistoryEntry
History returns a copy of the local moderation audit log, newest first.
func (*Moderator) InterceptAccept ¶
func (m *Moderator) InterceptAccept(_ lp2pnet.ConnMultiaddrs) bool
func (*Moderator) InterceptAddrDial ¶
func (*Moderator) InterceptSecured ¶
func (*Moderator) InterceptUpgraded ¶
func (*Moderator) IsAuthorBanned ¶
IsAuthorBanned, forum/chat'te AuthorKey olarak kullanılan hex-encoded ed25519 public key'in, ağ seviyesinde banlı bir peer'a ait olup olmadığını bildirir — bkz. AuthorKeyToPeerID. forum.Forum ve chatlog.Store bunu SetModerator ile bağlandıklarında handleMessage içinde çağırır; böylece bir moderatörün verdiği peer banı yalnızca yeni bağlantıları değil, o kişinin forum konularını/yanıtlarını ve sohbet mesajlarını da engeller.
func (*Moderator) IssueBan ¶
IssueBan applies a ban originated by THIS node locally via applyBan (so it takes effect immediately, without waiting for GossipSub's self-echo, which isn't guaranteed), then publishes it to the network. ban should come from SignFounderBan or SignModeratorBan.
func (*Moderator) IssueGrant ¶
func (m *Moderator) IssueGrant(founderPriv ed25519.PrivateKey, targetKeyHex string, expiresAt time.Time, permanent bool) (cert ModeratorCert, certPath string, err error)
IssueGrant builds and signs a ModeratorCert for targetKeyHex using founderPriv, records it in the local GrantedMods log, and writes a copy to dataDir/bans/mod_<ilk8>.json (the same on-disk convention andmod grant already uses). The founder is responsible for delivering the returned cert (or the written file) to the target out-of-band (e.g. via Özel Chat) — certs are bearer tokens, never broadcast over the network.
The freshly-signed cert is verified against m.founder via verifyCert before anything is recorded/written — mirroring the self-check every other Issue* method performs, so a wrong signing key fails loudly here instead of silently reporting success for a cert nobody else accepts.
func (*Moderator) IssueRevoke ¶
IssueRevoke applies a revoke originated by THIS node locally first (see IssueBan), publishes it, then marks the matching local GrantedMods entry (if any) as revoked.
func (*Moderator) IssueUnban ¶
IssueUnban applies an unban originated by THIS node locally first (see IssueBan), then publishes it.
func (*Moderator) PeerBanInfo ¶
PeerBanInfo reports pid's current ban, if any. ok is false if pid isn't banned (including an expired, non-permanent ban that just hasn't been swept by cleanupExpiredBans yet — see IsBanned's identical expiry check).
func (*Moderator) PublishBan ¶
func (*Moderator) PublishRevoke ¶
func (*Moderator) PublishSavedBans ¶
PublishSavedBans, dataDir/bans altındaki "ban_*.json"/"revoke_*.json"/ "unban_*.json" dosyalarını (andmod'un ürettiği ham kayıtlar) Envelope'a sarıp moderasyon topic'ine yayınlar. AND her başlangıçta bunu çağırır — böylece düğüm yeniden başladığında ya da ağa yeni katılan peer'lar bu eylemleri (yeniden) öğrenir.
func (*Moderator) PublishUnban ¶
func (*Moderator) Stop ¶
func (m *Moderator) Stop()
Stop, Start tarafından başlatılan arka plan goroutine'lerini durdurur ve hepsi tamamen sonlanana kadar bloklar. Özellikle testlerde, dataDir'i silmeden (ör. t.TempDir() temizliği) önce çağrılmalıdır — aksi halde hâlâ süren bir dosya yazımı (saveBans/saveRates/appendHistory) dizin silme işlemiyle yarışabilir ve Windows'ta "directory not empty" hatasına yol açabilir.
func (*Moderator) VerifyFounderSignature ¶
VerifyFounderSignature reports whether sig is a valid Ed25519 signature over payload made with the founder's own private key. Exported so other packages (forum, chatlog) can build their own founder-authorized message types (e.g. a moderator-issued post deletion) without duplicating access to the founder's public key.
func (*Moderator) VerifyModeratorCert ¶
func (m *Moderator) VerifyModeratorCert(cert ModeratorCert) bool
VerifyModeratorCert reports whether cert is a currently-valid moderator certificate signed by the founder — not expired, not exceeding maxCertDays, and not revoked. Exported so other packages (e.g. profile) can let a peer prove their moderator role without re-implementing the founder-signature/revocation checks.
type ModeratorCert ¶
type ModeratorCert struct {
ModeratorKey string `json:"moderator_key"`
// IssuedAt imzanın kapsadığı bir alandır (bkz. ModeratorCertPayload) —
// sertifikayı elinde tutan taraf bunu değiştirip iptali (revoke)
// atlatamaz. Bir sertifika, IssuedAt bir iptalden ÖNCEYSE geçersiz
// sayılır; SONRA yeniden verilmişse geçerlidir.
IssuedAt time.Time `json:"issued_at,omitempty"`
ExpiresAt time.Time `json:"expires_at,omitempty"`
Permanent bool `json:"permanent,omitempty"`
Sig string `json:"sig"`
}
func FindModCert ¶
func FindModCert(dataDir, myPubHex string) *ModeratorCert
func ResolveAuthority ¶
func ResolveAuthority(dataDir string, mod *Moderator, isFounder bool, myKeyHex string) (canAct bool, cert *ModeratorCert)
ResolveAuthority reports whether myKeyHex currently holds valid founder or moderator authority: founder status is checked first, and otherwise a moderator certificate is looked up on disk and verified (which also checks revocation — see VerifyModeratorCert). This is the ONE place this check should be made; cmd/and/main.go's resolveOwnModAuthority (plugin API delete/mod actions) and internal/tui/forum.go's resolveBanAuthority (TUI ban/unban flow) both call into this instead of independently re-deriving the same FindModCert+VerifyModeratorCert pairing, so a future change to revocation semantics can't be patched into one call site and missed in the other.
func SignModeratorCert ¶
func SignModeratorCert(founderPriv ed25519.PrivateKey, targetKeyHex string, expiresAt time.Time, permanent bool) ModeratorCert
SignModeratorCert builds a ModeratorCert granting targetKeyHex moderator authority, signed by founderPriv — only verifies anywhere on the network if founderPriv genuinely is the founder's key.
type PersistedBan ¶
type RevokeMsg ¶
type RevokeMsg struct {
ModeratorKey string `json:"moderator_key"`
IssuedAt time.Time `json:"issued_at"`
Sig string `json:"sig"`
}
func SignRevoke ¶
func SignRevoke(founderPriv ed25519.PrivateKey, targetKeyHex string) RevokeMsg
SignRevoke builds a RevokeMsg withdrawing targetKeyHex's moderator authority, signed by founderPriv.
type UnbanMsg ¶
type UnbanMsg struct {
BannedPeer string `json:"banned_peer"`
Cert ModeratorCert `json:"cert"`
IssuedAt time.Time `json:"issued_at"`
Sig string `json:"sig"`
}
UnbanMsg, bir moderatörün (geçerli bir sertifikayla) daha önce verdiği bir banı geri almasını sağlar — BanMsg'in kalıcılığının tek istisnası: aksi halde bir ban, süresi (en fazla maxBanDays) dolana kadar geri alınamazdı; hatalı ya da haksız bir ban için tek çare beklemek olurdu.
func SignFounderUnban ¶
func SignFounderUnban(founderPriv ed25519.PrivateKey, bannedPeer string) UnbanMsg
SignFounderUnban builds an UnbanMsg signed directly by the founder's own key (founderPriv), with no ModeratorCert attached.
func SignModeratorUnban ¶
func SignModeratorUnban(modPriv ed25519.PrivateKey, cert ModeratorCert, bannedPeer string) UnbanMsg
SignModeratorUnban builds an UnbanMsg signed by a moderator's own key (modPriv) using their granted cert — the shared reference implementation for both andmod's CLI and the TUI's in-app unban action.