forked from AdguardTeam/AdGuardHome
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pull request: 3835 check ports properly
Merge in DNS/adguard-home from 3835-imp-error-msg to master Updates AdguardTeam#3835. Squashed commit of the following: commit ba31cb6 Merge: 19c7dfc 4be69d3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 16 20:07:25 2021 +0300 Merge branch 'master' into 3835-imp-error-msg commit 19c7dfc Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 16 19:42:10 2021 +0300 all: imp more commit 5b9c6a3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 16 18:57:02 2021 +0300 all: introduce aghhttp commit 29caa17 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Dec 16 14:23:53 2021 +0300 all: imp more commit 754c020 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 15 20:53:41 2021 +0300 all: imp code, log changes commit ec712dd Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Wed Dec 15 18:40:54 2021 +0300 home: check ports properly
- Loading branch information
1 parent
e8a163e
commit 7f1b816
Showing
31 changed files
with
672 additions
and
345 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
// Package aghhttp provides some common methods to work with HTTP. | ||
package aghhttp | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"net/http" | ||
|
||
"github.com/AdguardTeam/golibs/log" | ||
) | ||
|
||
// OK responds with word OK. | ||
func OK(w http.ResponseWriter) { | ||
if _, err := io.WriteString(w, "OK\n"); err != nil { | ||
log.Error("couldn't write body: %s", err) | ||
} | ||
} | ||
|
||
// Error writes formatted message to w and also logs it. | ||
func Error(r *http.Request, w http.ResponseWriter, code int, format string, args ...interface{}) { | ||
text := fmt.Sprintf(format, args...) | ||
log.Error("%s %s: %s", r.Method, r.URL, text) | ||
http.Error(w, text, code) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,19 @@ | ||
//go:build openbsd || freebsd || linux | ||
// +build openbsd freebsd linux | ||
//go:build openbsd || freebsd || linux || darwin | ||
// +build openbsd freebsd linux darwin | ||
|
||
package aghnet | ||
|
||
// interfaceName is a string containing network interface's name. The name is | ||
// used in file walking methods. | ||
type interfaceName string | ||
import ( | ||
"io" | ||
"syscall" | ||
|
||
"github.com/AdguardTeam/golibs/errors" | ||
) | ||
|
||
func closePortChecker(c io.Closer) (err error) { | ||
return c.Close() | ||
} | ||
|
||
func isAddrInUse(err syscall.Errno) (ok bool) { | ||
return errors.Is(err, syscall.EADDRINUSE) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
//go:build !(linux || darwin || freebsd || openbsd) | ||
// +build !linux,!darwin,!freebsd,!openbsd | ||
|
||
package aghnet | ||
|
||
import ( | ||
"io" | ||
"syscall" | ||
"time" | ||
|
||
"github.com/AdguardTeam/AdGuardHome/internal/aghos" | ||
"github.com/AdguardTeam/golibs/errors" | ||
"golang.org/x/sys/windows" | ||
) | ||
|
||
func canBindPrivilegedPorts() (can bool, err error) { | ||
return aghos.HaveAdminRights() | ||
} | ||
|
||
func ifaceHasStaticIP(string) (ok bool, err error) { | ||
return false, aghos.Unsupported("checking static ip") | ||
} | ||
|
||
func ifaceSetStaticIP(string) (err error) { | ||
return aghos.Unsupported("setting static ip") | ||
} | ||
|
||
func closePortChecker(c io.Closer) (err error) { | ||
if err = c.Close(); err != nil { | ||
return err | ||
} | ||
|
||
// It seems that net.Listener.Close() doesn't close file descriptors right | ||
// away. We wait for some time and hope that this fd will be closed. | ||
// | ||
// TODO(e.burkov): Investigate the purpose of the line and perhaps use more | ||
// reliable approach. | ||
time.Sleep(100 * time.Millisecond) | ||
|
||
return nil | ||
} | ||
|
||
func isAddrInUse(err syscall.Errno) (ok bool) { | ||
return errors.Is(err, windows.WSAEADDRINUSE) | ||
} |
Oops, something went wrong.