Changeset 700 in code


Ignore:
Timestamp:
Nov 17, 2021, 11:29:23 AM (4 years ago)
Author:
contact
Message:

Add context to downstreamConn.handleMessageUnregistered

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/downstream.go

    r699 r700  
    629629
    630630func (dc *downstreamConn) handleMessageUnregistered(msg *irc.Message) error {
     631        ctx, cancel := context.WithTimeout(context.TODO(), handleDownstreamMessageTimeout)
     632        defer cancel()
     633
    631634        switch msg.Command {
    632635        case "NICK":
     
    698701                        case "PLAIN":
    699702                                dc.saslServer = sasl.NewPlainServer(sasl.PlainAuthenticator(func(identity, username, password string) error {
    700                                         return dc.authenticate(username, password)
     703                                        // TODO: we can't use the command context here, because it
     704                                        // gets cancelled once the command handler returns. SASL
     705                                        // might take multiple AUTHENTICATE commands to complete.
     706                                        return dc.authenticate(context.TODO(), username, password)
    701707                                }))
    702708                        default:
     
    806812        }
    807813        if dc.rawUsername != "" && dc.nick != "" && !dc.negotiatingCaps {
    808                 return dc.register()
     814                return dc.register(ctx)
    809815        }
    810816        return nil
     
    10691075}
    10701076
    1071 func (dc *downstreamConn) authenticate(username, password string) error {
     1077func (dc *downstreamConn) authenticate(ctx context.Context, username, password string) error {
    10721078        username, clientName, networkName := unmarshalUsername(username)
    10731079
    1074         u, err := dc.srv.db.GetUser(context.TODO(), username)
     1080        u, err := dc.srv.db.GetUser(ctx, username)
    10751081        if err != nil {
    10761082                dc.logger.Printf("failed authentication for %q: user not found: %v", username, err)
     
    10991105}
    11001106
    1101 func (dc *downstreamConn) register() error {
     1107func (dc *downstreamConn) register(ctx context.Context) error {
    11021108        if dc.registered {
    11031109                return fmt.Errorf("tried to register twice")
     
    11071113        dc.password = ""
    11081114        if dc.user == nil {
    1109                 if err := dc.authenticate(dc.rawUsername, password); err != nil {
     1115                if err := dc.authenticate(ctx, dc.rawUsername, password); err != nil {
    11101116                        return err
    11111117                }
Note: See TracChangeset for help on using the changeset viewer.