- Timestamp:
- Nov 8, 2021, 6:40:48 PM (4 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/downstream.go
r676 r677 2162 2162 }) 2163 2163 } 2164 handleServicePRIVMSG( dc, text)2164 handleServicePRIVMSG(ctx, dc, text) 2165 2165 continue 2166 2166 } -
trunk/service.go
r676 r677 40 40 usage string 41 41 desc string 42 handle func( dc *downstreamConn, params []string) error42 handle func(ctx context.Context, dc *downstreamConn, params []string) error 43 43 children serviceCommandSet 44 44 admin bool … … 114 114 } 115 115 116 func handleServicePRIVMSG( dc *downstreamConn, text string) {116 func handleServicePRIVMSG(ctx context.Context, dc *downstreamConn, text string) { 117 117 words, err := splitWords(text) 118 118 if err != nil { … … 145 145 } 146 146 147 if err := cmd.handle( dc, params); err != nil {147 if err := cmd.handle(ctx, dc, params); err != nil { 148 148 sendServicePRIVMSG(dc, fmt.Sprintf("error: %v", err)) 149 149 } … … 323 323 } 324 324 325 func handleServiceHelp( dc *downstreamConn, params []string) error {325 func handleServiceHelp(ctx context.Context, dc *downstreamConn, params []string) error { 326 326 if len(params) > 0 { 327 327 cmd, rest, err := serviceCommands.Get(params) … … 474 474 } 475 475 476 func handleServiceNetworkCreate( dc *downstreamConn, params []string) error {476 func handleServiceNetworkCreate(ctx context.Context, dc *downstreamConn, params []string) error { 477 477 fs := newNetworkFlagSet() 478 478 if err := fs.Parse(params); err != nil { … … 491 491 } 492 492 493 network, err := dc.user.createNetwork(c ontext.TODO(), record)493 network, err := dc.user.createNetwork(ctx, record) 494 494 if err != nil { 495 495 return fmt.Errorf("could not create network: %v", err) … … 500 500 } 501 501 502 func handleServiceNetworkStatus( dc *downstreamConn, params []string) error {502 func handleServiceNetworkStatus(ctx context.Context, dc *downstreamConn, params []string) error { 503 503 n := 0 504 504 dc.user.forEachNetwork(func(net *network) { … … 546 546 } 547 547 548 func handleServiceNetworkUpdate( dc *downstreamConn, params []string) error {548 func handleServiceNetworkUpdate(ctx context.Context, dc *downstreamConn, params []string) error { 549 549 if len(params) < 1 { 550 550 return fmt.Errorf("expected at least one argument") … … 566 566 } 567 567 568 network, err := dc.user.updateNetwork(c ontext.TODO(), &record)568 network, err := dc.user.updateNetwork(ctx, &record) 569 569 if err != nil { 570 570 return fmt.Errorf("could not update network: %v", err) … … 575 575 } 576 576 577 func handleServiceNetworkDelete( dc *downstreamConn, params []string) error {577 func handleServiceNetworkDelete(ctx context.Context, dc *downstreamConn, params []string) error { 578 578 if len(params) != 1 { 579 579 return fmt.Errorf("expected exactly one argument") … … 585 585 } 586 586 587 if err := dc.user.deleteNetwork(c ontext.TODO(), net.ID); err != nil {587 if err := dc.user.deleteNetwork(ctx, net.ID); err != nil { 588 588 return err 589 589 } … … 593 593 } 594 594 595 func handleServiceNetworkQuote( dc *downstreamConn, params []string) error {595 func handleServiceNetworkQuote(ctx context.Context, dc *downstreamConn, params []string) error { 596 596 if len(params) != 2 { 597 597 return fmt.Errorf("expected exactly two arguments") … … 627 627 } 628 628 629 func handleServiceCertFPGenerate( dc *downstreamConn, params []string) error {629 func handleServiceCertFPGenerate(ctx context.Context, dc *downstreamConn, params []string) error { 630 630 fs := newFlagSet() 631 631 keyType := fs.String("key-type", "rsa", "key type to generate (rsa, ecdsa, ed25519)") … … 658 658 net.SASL.Mechanism = "EXTERNAL" 659 659 660 if err := dc.srv.db.StoreNetwork(c ontext.TODO(), dc.user.ID, &net.Network); err != nil {660 if err := dc.srv.db.StoreNetwork(ctx, dc.user.ID, &net.Network); err != nil { 661 661 return err 662 662 } … … 667 667 } 668 668 669 func handleServiceCertFPFingerprints( dc *downstreamConn, params []string) error {669 func handleServiceCertFPFingerprints(ctx context.Context, dc *downstreamConn, params []string) error { 670 670 if len(params) != 1 { 671 671 return fmt.Errorf("expected exactly one argument") … … 685 685 } 686 686 687 func handleServiceSASLSetPlain( dc *downstreamConn, params []string) error {687 func handleServiceSASLSetPlain(ctx context.Context, dc *downstreamConn, params []string) error { 688 688 if len(params) != 3 { 689 689 return fmt.Errorf("expected exactly 3 arguments") … … 699 699 net.SASL.Mechanism = "PLAIN" 700 700 701 if err := dc.srv.db.StoreNetwork(c ontext.TODO(), dc.user.ID, &net.Network); err != nil {701 if err := dc.srv.db.StoreNetwork(ctx, dc.user.ID, &net.Network); err != nil { 702 702 return err 703 703 } … … 707 707 } 708 708 709 func handleServiceSASLReset( dc *downstreamConn, params []string) error {709 func handleServiceSASLReset(ctx context.Context, dc *downstreamConn, params []string) error { 710 710 if len(params) != 1 { 711 711 return fmt.Errorf("expected exactly one argument") … … 723 723 net.SASL.Mechanism = "" 724 724 725 if err := dc.srv.db.StoreNetwork(c ontext.TODO(), dc.user.ID, &net.Network); err != nil {725 if err := dc.srv.db.StoreNetwork(ctx, dc.user.ID, &net.Network); err != nil { 726 726 return err 727 727 } … … 731 731 } 732 732 733 func handleUserCreate( dc *downstreamConn, params []string) error {733 func handleUserCreate(ctx context.Context, dc *downstreamConn, params []string) error { 734 734 fs := newFlagSet() 735 735 username := fs.String("username", "", "") … … 774 774 } 775 775 776 func handleUserUpdate( dc *downstreamConn, params []string) error {776 func handleUserUpdate(ctx context.Context, dc *downstreamConn, params []string) error { 777 777 var password, realname *string 778 778 var admin *bool … … 838 838 } 839 839 840 if err := dc.user.updateUser(c ontext.TODO(), &record); err != nil {840 if err := dc.user.updateUser(ctx, &record); err != nil { 841 841 return err 842 842 } … … 848 848 } 849 849 850 func handleUserDelete( dc *downstreamConn, params []string) error {850 func handleUserDelete(ctx context.Context, dc *downstreamConn, params []string) error { 851 851 if len(params) != 1 { 852 852 return fmt.Errorf("expected exactly one argument") … … 861 861 u.stop() 862 862 863 if err := dc.srv.db.DeleteUser(c ontext.TODO(), u.ID); err != nil {863 if err := dc.srv.db.DeleteUser(ctx, u.ID); err != nil { 864 864 return fmt.Errorf("failed to delete user: %v", err) 865 865 } … … 869 869 } 870 870 871 func handleServiceChannelStatus( dc *downstreamConn, params []string) error {871 func handleServiceChannelStatus(ctx context.Context, dc *downstreamConn, params []string) error { 872 872 var defaultNetworkName string 873 873 if dc.network != nil { … … 989 989 } 990 990 991 func handleServiceChannelUpdate( dc *downstreamConn, params []string) error {991 func handleServiceChannelUpdate(ctx context.Context, dc *downstreamConn, params []string) error { 992 992 if len(params) < 1 { 993 993 return fmt.Errorf("expected at least one argument") … … 1016 1016 uc.updateChannelAutoDetach(upstreamName) 1017 1017 1018 if err := dc.srv.db.StoreChannel(c ontext.TODO(), uc.network.ID, ch); err != nil {1018 if err := dc.srv.db.StoreChannel(ctx, uc.network.ID, ch); err != nil { 1019 1019 return fmt.Errorf("failed to update channel: %v", err) 1020 1020 } … … 1024 1024 } 1025 1025 1026 func handleServiceServerStatus( dc *downstreamConn, params []string) error {1027 dbStats, err := dc.user.srv.db.Stats(c ontext.TODO())1026 func handleServiceServerStatus(ctx context.Context, dc *downstreamConn, params []string) error { 1027 dbStats, err := dc.user.srv.db.Stats(ctx) 1028 1028 if err != nil { 1029 1029 return err … … 1034 1034 } 1035 1035 1036 func handleServiceServerNotice( dc *downstreamConn, params []string) error {1036 func handleServiceServerNotice(ctx context.Context, dc *downstreamConn, params []string) error { 1037 1037 if len(params) != 1 { 1038 1038 return fmt.Errorf("expected exactly one argument")
Note:
See TracChangeset
for help on using the changeset viewer.