Changeset 385 in code for trunk/user.go


Ignore:
Timestamp:
Aug 11, 2020, 8:59:06 AM (5 years ago)
Author:
contact
Message:

Add an ident server

Closes: https://todo.sr.ht/~emersion/soju/69

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/user.go

    r377 r385  
    22
    33import (
     4        "crypto/sha256"
     5        "encoding/base64"
     6        "encoding/binary"
    47        "fmt"
    58        "time"
     
    100103}
    101104
     105func userIdent(u *User) string {
     106        // The ident is a string we will send to upstream servers in clear-text.
     107        // For privacy reasons, make sure it doesn't expose any meaningful user
     108        // metadata. We just use the base64-encoded hashed ID, so that people don't
     109        // start relying on the string being an integer or following a pattern.
     110        var b [64]byte
     111        binary.LittleEndian.PutUint64(b[:], uint64(u.ID))
     112        h := sha256.Sum256(b[:])
     113        return base64.RawStdEncoding.EncodeToString(h[:])
     114}
     115
    102116func (net *network) run() {
    103117        var lastTry time.Time
     
    119133                        net.user.events <- eventUpstreamConnectionError{net, fmt.Errorf("failed to connect: %v", err)}
    120134                        continue
     135                }
     136
     137                if net.user.srv.Identd != nil {
     138                        net.user.srv.Identd.Store(uc.RemoteAddr().String(), uc.LocalAddr().String(), userIdent(&net.user.User))
    121139                }
    122140
     
    139157                uc.Close()
    140158                net.user.events <- eventUpstreamDisconnected{uc}
     159
     160                if net.user.srv.Identd != nil {
     161                        net.user.srv.Identd.Delete(uc.RemoteAddr().String(), uc.LocalAddr().String())
     162                }
    141163        }
    142164}
Note: See TracChangeset for help on using the changeset viewer.