lint, gitignore, GNU Makefile to make things simpler
This commit is contained in:
parent
006a4f9d6d
commit
7df5779a24
5 changed files with 38 additions and 25 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.idea/
|
12
Makefile
Normal file
12
Makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
test: check
|
||||
|
||||
check: lint
|
||||
go test -v
|
||||
|
||||
lint:
|
||||
gofmt -w=true -s=true -l=true ./
|
||||
golint ./...
|
||||
go vet ./...
|
||||
|
||||
|
||||
|
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
|||
module github.com/chrj/smtpd
|
||||
|
||||
go 1.14
|
||||
go 1.19
|
||||
|
|
42
smtpd.go
42
smtpd.go
|
@ -55,10 +55,10 @@ type Server struct {
|
|||
|
||||
// mu guards doneChan and makes closing it and listener atomic from
|
||||
// perspective of Serve()
|
||||
mu sync.Mutex
|
||||
doneChan chan struct{}
|
||||
listener *net.Listener
|
||||
waitgrp sync.WaitGroup
|
||||
mu sync.Mutex
|
||||
doneChan chan struct{}
|
||||
listener *net.Listener
|
||||
waitgrp sync.WaitGroup
|
||||
inShutdown atomicBool // true when server is in shutdown
|
||||
}
|
||||
|
||||
|
@ -66,10 +66,11 @@ type Server struct {
|
|||
type Protocol string
|
||||
|
||||
const (
|
||||
// SMTP
|
||||
// SMTP means Simple Mail Transfer Protocol
|
||||
SMTP Protocol = "SMTP"
|
||||
|
||||
// Extended SMTP
|
||||
// ESMTP means Extended Simple Mail Transfer Protocol, because it has some extra features
|
||||
// Simple Mail Transfer Protocol doesn't have
|
||||
ESMTP = "ESMTP"
|
||||
)
|
||||
|
||||
|
@ -228,7 +229,7 @@ func (srv *Server) Shutdown(wait bool) error {
|
|||
// First close the listener
|
||||
srv.mu.Lock()
|
||||
if srv.listener != nil {
|
||||
lnerr = (*srv.listener).Close();
|
||||
lnerr = (*srv.listener).Close()
|
||||
}
|
||||
srv.closeDoneChanLocked()
|
||||
srv.mu.Unlock()
|
||||
|
@ -254,7 +255,7 @@ func (srv *Server) Wait() error {
|
|||
|
||||
// Address returns the listening address of the server
|
||||
func (srv *Server) Address() net.Addr {
|
||||
return (*srv.listener).Addr();
|
||||
return (*srv.listener).Addr()
|
||||
}
|
||||
|
||||
func (srv *Server) configureDefaults() {
|
||||
|
@ -433,28 +434,27 @@ func (session *session) close() {
|
|||
session.conn.Close()
|
||||
}
|
||||
|
||||
|
||||
// From net/http/server.go
|
||||
|
||||
func (s *Server) shuttingDown() bool {
|
||||
return s.inShutdown.isSet()
|
||||
func (srv *Server) shuttingDown() bool {
|
||||
return srv.inShutdown.isSet()
|
||||
}
|
||||
|
||||
func (s *Server) getDoneChan() <-chan struct{} {
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
return s.getDoneChanLocked()
|
||||
func (srv *Server) getDoneChan() <-chan struct{} {
|
||||
srv.mu.Lock()
|
||||
defer srv.mu.Unlock()
|
||||
return srv.getDoneChanLocked()
|
||||
}
|
||||
|
||||
func (s *Server) getDoneChanLocked() chan struct{} {
|
||||
if s.doneChan == nil {
|
||||
s.doneChan = make(chan struct{})
|
||||
func (srv *Server) getDoneChanLocked() chan struct{} {
|
||||
if srv.doneChan == nil {
|
||||
srv.doneChan = make(chan struct{})
|
||||
}
|
||||
return s.doneChan
|
||||
return srv.doneChan
|
||||
}
|
||||
|
||||
func (s *Server) closeDoneChanLocked() {
|
||||
ch := s.getDoneChanLocked()
|
||||
func (srv *Server) closeDoneChanLocked() {
|
||||
ch := srv.getDoneChanLocked()
|
||||
select {
|
||||
case <-ch:
|
||||
// Already closed. Don't close again.
|
||||
|
|
|
@ -394,11 +394,11 @@ func TestAuthNotSupported(t *testing.T) {
|
|||
func TestAuthBypass(t *testing.T) {
|
||||
|
||||
addr, closer := runsslserver(t, &smtpd.Server{
|
||||
Authenticator: func(peer smtpd.Peer, username, password string) error {
|
||||
Authenticator: func(peer smtpd.Peer, username, password string) error {
|
||||
return smtpd.Error{Code: 550, Message: "Denied"}
|
||||
},
|
||||
ForceTLS: true,
|
||||
ProtocolLogger: log.New(os.Stdout, "log: ", log.Lshortfile),
|
||||
ForceTLS: true,
|
||||
ProtocolLogger: log.New(os.Stdout, "log: ", log.Lshortfile),
|
||||
})
|
||||
|
||||
defer closer()
|
||||
|
|
Loading…
Add table
Reference in a new issue