mirror of
https://github.com/hanzoai/tasks.git
synced 2026-10-04 02:04:03 +00:00
## What changed?
<!-- Describe what has changed in this PR -->
Remove license header from every file. Because it is really hard to
follow in this PR here is the summary:
1. License header is removed from all `.go` and `.proto` files
:fireworks::fireworks:🎆.
2. `LICENSE` file in the root directory has only Temporal and Uber
copyrights.
3. 5 other `LICENSE` files added to the packages which have copyrights
different from Temporal and Uber: Datadog, Xargin, "Mat Ryer, Tyler
Bunnell and contributors".
4. `license_file` flag is removed from all code generation tools.
5. `copyright_file` flag is removed from `go:generate mockgen`
directive.
6. All copyright related targets are removed from `Makefile`.
7. Updated Temporal copyright year to 2025 everywhere.
## Why?
<!-- Tell your future self why have you made these changes -->
I double checked with legal department that it is not needed to have
license header in every file. One file per repo is enough. I put all
copyrights to the root `LICENSE` file and removed header from all other
files. Also updated tools and `Makefile`.
80 lines
1.7 KiB
Go
80 lines
1.7 KiB
Go
package config
|
|
|
|
// ** This code is copied from tchannel, we would like to not take dependency on tchannel code **
|
|
|
|
import (
|
|
"errors"
|
|
"net"
|
|
)
|
|
|
|
// scoreAddr scores how likely the given addr is to be a remote address and returns the
|
|
// IP to use when listening. Any address which receives a negative score should not be used.
|
|
// Scores are calculated as:
|
|
// -1 for any unknown IP addreseses.
|
|
// +300 for IPv4 addresses
|
|
// +100 for non-local addresses, extra +100 for "up" interaces.
|
|
func scoreAddr(iface net.Interface, addr net.Addr) (int, net.IP) {
|
|
var ip net.IP
|
|
if netAddr, ok := addr.(*net.IPNet); ok {
|
|
ip = netAddr.IP
|
|
} else if netIP, ok := addr.(*net.IPAddr); ok {
|
|
ip = netIP.IP
|
|
} else {
|
|
return -1, nil
|
|
}
|
|
|
|
var score int
|
|
if ip.To4() != nil {
|
|
score += 300
|
|
}
|
|
if iface.Flags&net.FlagLoopback == 0 && !ip.IsLoopback() {
|
|
score += 100
|
|
if iface.Flags&net.FlagUp != 0 {
|
|
score += 100
|
|
}
|
|
}
|
|
return score, ip
|
|
}
|
|
|
|
// ListenIP returns the IP to bind to in Listen. It tries to find an IP that can be used
|
|
// by other machines to reach this machine.
|
|
func ListenIP() (net.IP, error) {
|
|
interfaces, err := net.Interfaces()
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
bestScore := -1
|
|
var bestIP net.IP
|
|
// Select the highest scoring IP as the best IP.
|
|
for _, iface := range interfaces {
|
|
addrs, err := iface.Addrs()
|
|
if err != nil {
|
|
// Skip this interface if there is an error.
|
|
continue
|
|
}
|
|
|
|
for _, addr := range addrs {
|
|
score, ip := scoreAddr(iface, addr)
|
|
if score > bestScore {
|
|
bestScore = score
|
|
bestIP = ip
|
|
}
|
|
}
|
|
}
|
|
|
|
if bestScore == -1 {
|
|
return nil, errors.New("no addresses to listen on")
|
|
}
|
|
|
|
return bestIP, nil
|
|
}
|
|
|
|
func mustParseMAC(s string) net.HardwareAddr {
|
|
addr, err := net.ParseMAC(s)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
return addr
|
|
}
|