├── bin ├── mac │ └── build.sh ├── linux │ └── build.sh ├── linux-arm │ └── build.sh └── windows │ └── build.sh ├── .gitignore ├── .github └── workflows │ └── go.yml ├── README.md ├── natgo └── natgo.go ├── natgo-client.go ├── natgo-server.go └── LICENSE /bin/mac/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=bin/mac 3 | go build -o $dir/natgo-client natgo-client.go 4 | go build -o $dir/natgo-server natgo-server.go 5 | cd $dir 6 | tar czvf natgo-mac.tar.gz natgo-client natgo-server -------------------------------------------------------------------------------- /bin/linux/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=bin/linux 3 | GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $dir/natgo-client natgo-client.go 4 | GOOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o $dir/natgo-server natgo-server.go 5 | cd $dir 6 | tar czvf natgo-linux.tar.gz natgo-client natgo-server -------------------------------------------------------------------------------- /bin/linux-arm/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=bin/linux-arm 3 | GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -o $dir/natgo-client natgo-client.go 4 | GOOS=linux GOARCH=arm CGO_ENABLED=0 go build -o $dir/natgo-server natgo-server.go 5 | cd $dir 6 | tar czvf natgo-linux-arm.tar.gz natgo-client natgo-server -------------------------------------------------------------------------------- /bin/windows/build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | dir=bin/windows 3 | GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o $dir/natgo-client.exe natgo-client.go 4 | GOOS=windows GOARCH=amd64 CGO_ENABLED=0 go build -o $dir/natgo-server.exe natgo-server.go 5 | cd $dir 6 | tar czvf natgo-windows.tar.gz natgo-client.exe natgo-server.exe -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Compiled Object files, Static and Dynamic libs (Shared Objects) 2 | *.o 3 | *.a 4 | *.so 5 | 6 | # Folders 7 | _obj 8 | _test 9 | 10 | # Architecture specific extensions/prefixes 11 | *.[568vq] 12 | [568vq].out 13 | 14 | *.cgo1.go 15 | *.cgo2.c 16 | _cgo_defun.c 17 | _cgo_gotypes.go 18 | _cgo_export.* 19 | 20 | _testmain.go 21 | 22 | *.exe 23 | *.test 24 | *.prof 25 | 26 | .idea 27 | *.iml 28 | -------------------------------------------------------------------------------- /.github/workflows/go.yml: -------------------------------------------------------------------------------- 1 | name: Go 2 | 3 | on: 4 | push: 5 | branches: [ master ] 6 | pull_request: 7 | branches: [ master ] 8 | 9 | jobs: 10 | 11 | build: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | 16 | - name: Set up Go 17 | uses: actions/setup-go@v2 18 | with: 19 | go-version: 1.17 20 | 21 | - name: Build 22 | run: go build -v ./... 23 | 24 | - name: Test 25 | run: go test -v ./... 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Natgo 2 | A tool that can help nodes behinds NAT be accessed by outside. 3 | 4 | 5 | # Usage 6 | 7 | ## Server 8 | #### Usage 9 | 10 | ``` 11 | Usage: natgo-server [servicePort] ... 12 | ``` 13 | 14 | #### Example: 15 | 16 | ``` 17 | $ natgo-server 5000 6022 6080 18 | Start NAT server 19 | Start Guest thread on port 6080 20 | Listen on port:6080 [::]:6080 21 | Start NAT thread on port 5000 22 | Listen on port:5000 [::]:5000 23 | Start Guest thread on port 6022 24 | Listen on port:6022 [::]:6022 25 | ``` 26 | The serve will listen on management port 5000 and listen on service port 6022 and 6080. Then the client can map the port 6022 for its port 22 and 6080 for its port 80. 27 | 28 | ## Client 29 | 30 | #### Usage 31 | ``` 32 | Usage: natgo-client [servicePort:targetHost:port] 33 | ``` 34 | 35 | #### Example 36 | 37 | ``` 38 | $ natgo-client :5000 6022:localhost:22 6080:localhost:80 39 | ``` 40 | The client is a node behind a NAT which can only connect the server. After connecting to server, the user can connect to the client's ssh port by connecting server's 6022 port and client's http port by server's 6080 port. 41 | 42 | ## Security 43 | 44 | For now, the tool is only a port forwarder. It is not responsible for authentication of the client and server. The security should be considered by the application which providing the service. 45 | 46 | # License 47 | 48 | The Apache2.0 License -------------------------------------------------------------------------------- /natgo/natgo.go: -------------------------------------------------------------------------------- 1 | package natgo 2 | 3 | import ( 4 | "fmt" 5 | "net" 6 | "errors" 7 | "encoding/binary" 8 | _"time" 9 | ) 10 | 11 | const CMD_HEART_BEAT_REQUEST = 0 12 | const CMD_HEART_BEAT_RESPONSE = 1 13 | const CMD_REGISTER_CLIENT_REQUEST = 2 14 | const CMD_REGISTER_CLIENT_RESPONSE = 3 15 | 16 | const CMD_SERVER_START_SESSION_REQUEST = 4 17 | const CMD_SERVER_START_SESSION_RESPONSE = 5 18 | 19 | const CMD_CLIENT_REPLY_SESSION_REQUEST = 6 20 | const CMD_CLIENT_REPLY_SESSION_RESPONSE = 7 21 | 22 | func HeartBeatRequest(conn net.Conn) error { 23 | fmt.Println("ClientHeartBeatRequest") 24 | request := make([]byte, 1) 25 | request[0] = CMD_HEART_BEAT_REQUEST 26 | _, err := conn.Write(request) 27 | fmt.Println("Write to peer.") 28 | 29 | if (err != nil) { 30 | fmt.Println("Failed to write to peer.") 31 | } 32 | return err 33 | } 34 | 35 | func ClientRegisterRequest(conn net.Conn, service string) error { 36 | fmt.Println("ClientRegisterRequest") 37 | request := make([]byte, 1) 38 | request[0] = CMD_REGISTER_CLIENT_REQUEST 39 | serviceBytes := []byte(service) 40 | conn.Write(request) 41 | fmt.Println("Write to server:", service, serviceBytes) 42 | size, err := conn.Write(serviceBytes) 43 | fmt.Println("write result:", size, err) 44 | if (err != nil) { 45 | return err 46 | } 47 | response := make([]byte, 1) 48 | _, err = conn.Read(response) 49 | if (err != nil) { 50 | return err 51 | } 52 | if (response[0] != CMD_REGISTER_CLIENT_RESPONSE) { 53 | return errors.New("Invalid response") 54 | } else { 55 | fmt.Println("Get client register response") 56 | } 57 | return nil 58 | } 59 | 60 | func ClientReplySessionRequest(conn net.Conn, sessionId int32) error { 61 | fmt.Println("ClientReplySessionRequest, session:", sessionId) 62 | data := append([]byte{CMD_CLIENT_REPLY_SESSION_REQUEST}, Int32ToBytes(sessionId)...) 63 | 64 | conn.Write(data) 65 | response := make([]byte, 1) 66 | conn.Read(response) 67 | if (response[0] != CMD_CLIENT_REPLY_SESSION_RESPONSE) { 68 | return errors.New("Invalid response") 69 | } else { 70 | fmt.Println("Get client reply session response ") 71 | } 72 | return nil 73 | } 74 | 75 | func ServerStartSessionRequest(conn net.Conn, requestId int32, guestPort string) error { 76 | fmt.Println("ServerStartSessionRequest") 77 | cmd := []byte{CMD_SERVER_START_SESSION_REQUEST} 78 | var data = append(cmd, Int32ToBytes(requestId)...) 79 | data = append(data, []byte(guestPort)...) 80 | conn.Write(data) 81 | return nil 82 | } 83 | 84 | func transferData(src, dst net.Conn) { 85 | var buffer = make([]byte, 4096) 86 | for { 87 | size, err := src.Read(buffer) 88 | if err != nil { 89 | fmt.Println("error during transferData", err) 90 | src.Close() 91 | dst.Close() 92 | break 93 | } 94 | value := buffer[:size] 95 | 96 | _, err2 := dst.Write(value) 97 | if err2 != nil { 98 | fmt.Println("error during transferData", err2) 99 | src.Close() 100 | dst.Close() 101 | break 102 | } 103 | } 104 | } 105 | 106 | func ConnectionExchange(src, dst net.Conn) { 107 | go transferData(src, dst) 108 | go transferData(dst, src) 109 | } 110 | 111 | func Int64ToBytes(i int64) []byte { 112 | var buf = make([]byte, 8) 113 | binary.BigEndian.PutUint64(buf, uint64(i)) 114 | return buf 115 | } 116 | 117 | func BytesToInt64(buf []byte) int64 { 118 | return int64(binary.BigEndian.Uint64(buf)) 119 | } 120 | 121 | func Int32ToBytes(i int32) []byte { 122 | var buf = make([]byte, 4) 123 | binary.BigEndian.PutUint32(buf, uint32(i)) 124 | return buf 125 | } 126 | 127 | func BytesToInt32(buf []byte) int32 { 128 | return int32(binary.BigEndian.Uint32(buf)) 129 | } 130 | -------------------------------------------------------------------------------- /natgo-client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "./natgo" 6 | "sync" 7 | "os" 8 | "time" 9 | "strings" 10 | "errors" 11 | "log" 12 | ) 13 | 14 | var serviceMap = make(map[string]string) 15 | var mgrChannelLockForClient = sync.Mutex{} 16 | 17 | var isServerAlive = true 18 | 19 | func main() { 20 | log.Println("Start NAT client") 21 | if len(os.Args) < 3 { 22 | log.Println("Usage: natgo-client [servicePort:targetHost:port] ") 23 | return 24 | } 25 | remoteAddr := os.Args[1] 26 | targetAddresses := os.Args[2:] 27 | var services = "" 28 | for _, targetAddr := range targetAddresses { 29 | i := strings.Index(targetAddr, ":") 30 | service := targetAddr[0:i] 31 | targetAddr = targetAddr[i + 1:] 32 | serviceMap[service] = targetAddr 33 | services += service 34 | services += "," 35 | } 36 | services = strings.Trim(services, ",") 37 | log.Println(services) 38 | 39 | log.Println("Connect to control address ", remoteAddr) 40 | wg := sync.WaitGroup{} 41 | wg.Add(1) 42 | for { 43 | connRemote, err := net.DialTimeout("tcp", remoteAddr, 10 * time.Second) 44 | if err != nil { 45 | log.Println("Can't connect to remote: ", err) 46 | time.Sleep(10 * time.Second) 47 | continue 48 | } 49 | 50 | connRemote.SetReadDeadline(time.Now().Add(5 * time.Second)) 51 | 52 | err = natgo.ClientRegisterRequest(connRemote, services) 53 | if err != nil { 54 | log.Println("Can not register to server.") 55 | continue 56 | } 57 | connRemote.SetReadDeadline(time.Time{}) 58 | 59 | go heartBeat(connRemote) 60 | for { 61 | sessionId, service, err := serverStartSessionResponse(connRemote) 62 | if err == nil { 63 | targetAddr := serviceMap[service] 64 | work(remoteAddr, targetAddr, sessionId) 65 | } else { 66 | log.Println("Failed to start session with server.") 67 | connRemote.Close() 68 | break 69 | } 70 | } 71 | } 72 | 73 | wg.Wait() 74 | } 75 | 76 | func heartBeat(conn net.Conn) { 77 | for { 78 | time.Sleep(30 * time.Second) 79 | log.Println("Begin heart beat") 80 | log.Println("Get mgr conn lock") 81 | mgrChannelLockForClient.Lock() 82 | isServerAlive = false 83 | _, err := conn.Write([]byte{natgo.CMD_HEART_BEAT_REQUEST}) 84 | if err != nil { 85 | log.Println("Failed to send heartbeat request to server, close the connection.", err) 86 | conn.Close() 87 | mgrChannelLockForClient.Unlock() 88 | return 89 | } 90 | 91 | time.Sleep(2 * time.Second) //waiting for response 92 | 93 | if isServerAlive { 94 | log.Println("Get heartbeat response from server") 95 | } else { 96 | log.Println("Failed to get heartbeat response, close the connection.", err) 97 | conn.Close() 98 | mgrChannelLockForClient.Unlock() 99 | return 100 | } 101 | log.Println("Release mgr lock") 102 | mgrChannelLockForClient.Unlock() 103 | log.Println("Done heartbeat") 104 | } 105 | } 106 | 107 | func work(remoteAddr, targetAddr string, sessionId int32) { 108 | log.Println("Connecting target host ", targetAddr) 109 | targetConn := connectPort(targetAddr) 110 | if targetConn == nil { 111 | log.Println("Failed to connect to target addr") 112 | return 113 | } 114 | 115 | log.Println("Connecting to session remoteAddr ", remoteAddr) 116 | sessionConn := connectPort(remoteAddr) 117 | if sessionConn == nil { 118 | log.Println("Failed to connect to remote addr") 119 | return 120 | } 121 | natgo.ClientReplySessionRequest(sessionConn, sessionId) 122 | 123 | log.Println("Begin transfer data ...") 124 | 125 | natgo.ConnectionExchange(targetConn, sessionConn) 126 | } 127 | 128 | func connectPort(remoteAddr string) net.Conn { 129 | conn, err := net.DialTimeout("tcp", remoteAddr, 5 * time.Second) 130 | if err != nil { 131 | log.Println("Can't connect to addr: ", err) 132 | return nil 133 | } 134 | log.Println("Connectted:", conn.RemoteAddr()) 135 | return conn 136 | } 137 | 138 | func serverStartSessionResponse(conn net.Conn) (int32, string, error) { 139 | log.Println("ServerStartSessionResponse") 140 | for { 141 | request := make([]byte, 20) 142 | log.Println("Begin read cmd...") 143 | _, err := conn.Read(request) 144 | if err != nil { 145 | return 0, "", err 146 | } 147 | log.Println("Read cmd:", request) 148 | if request[0] == natgo.CMD_HEART_BEAT_RESPONSE { 149 | log.Println("Get heart beat cmd.") 150 | isServerAlive = true 151 | continue 152 | } else if request[0] != natgo.CMD_SERVER_START_SESSION_REQUEST { 153 | log.Println("Invalid cmd") 154 | return 0, "", errors.New("invalid cmd from server") 155 | } 156 | requestId := natgo.BytesToInt32(request[1:5]) 157 | log.Println("request id:", requestId) 158 | 159 | serviceBuffer := request[5:] 160 | 161 | service := string(serviceBuffer) 162 | service = strings.Trim(service, "\x00") 163 | log.Println("Client got service:", service) 164 | 165 | response := make([]byte, 1) 166 | response[0] = natgo.CMD_SERVER_START_SESSION_RESPONSE 167 | log.Println("Sending response ", response) 168 | mgrChannelLockForClient.Lock() 169 | conn.Write(response) 170 | mgrChannelLockForClient.Unlock() 171 | log.Println("Sent CMD_SERVER_START_SESSION_RESPONSE response") 172 | return requestId, service, nil 173 | } 174 | } 175 | -------------------------------------------------------------------------------- /natgo-server.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net" 5 | "sync" 6 | "./natgo" 7 | "os" 8 | "strings" 9 | "time" 10 | "math/rand" 11 | "log" 12 | ) 13 | 14 | var natConnectionPool = make(map[string]net.Conn) 15 | var waitingGuestConnectionPool = make(map[int32]net.Conn) 16 | 17 | var mgrChannelLock = sync.Mutex{} 18 | 19 | func main() { 20 | log.Println("Start NAT server") 21 | if len(os.Args) < 3 { 22 | log.Println("Usage: natgo-server [servicePort] ...") 23 | return 24 | } 25 | 26 | go listenForNAT(os.Args[1]) 27 | listenForGuests(os.Args[2:]) 28 | wg := sync.WaitGroup{} 29 | wg.Add(1) 30 | wg.Wait() 31 | } 32 | func listenForNAT(localPort string) { 33 | log.Println("Start NAT thread on port " + localPort) 34 | ln, err := net.Listen("tcp", ":" + localPort) 35 | if err != nil { 36 | log.Println(err) 37 | panic(err) 38 | } 39 | log.Println("Listen on port:" + localPort, ln.Addr()) 40 | 41 | for { 42 | conn, err := ln.Accept() 43 | if err != nil { 44 | log.Println(err) 45 | conn.Close() 46 | } else { 47 | log.Println("Got a new connection from nat:", conn.RemoteAddr()) 48 | go handleClient(conn) 49 | } 50 | } 51 | } 52 | 53 | func handleClient(conn net.Conn) error { 54 | log.Println("handleClient") 55 | request := make([]byte, 1) 56 | conn.Read(request) 57 | 58 | cmd := request[0] 59 | if cmd == natgo.CMD_REGISTER_CLIENT_REQUEST { 60 | log.Println("Get register request from client.") 61 | portBuffer := make([]byte, 1024) 62 | conn.Read(portBuffer) 63 | portStr := string(portBuffer) 64 | portStr = strings.Trim(portStr, "\x00") 65 | log.Println("Port service from client:", portStr) 66 | response := make([]byte, 1) 67 | response[0] = natgo.CMD_REGISTER_CLIENT_RESPONSE 68 | conn.Write(response) 69 | log.Println("Send client register response") 70 | services := strings.Split(portStr, ",") 71 | for _, v := range services { 72 | oldConn := natConnectionPool[v] 73 | if oldConn != nil { 74 | oldConn.Close() 75 | oldConn = nil 76 | } 77 | natConnectionPool[v] = conn 78 | } 79 | go processMgrChannel(conn) 80 | } else if cmd == natgo.CMD_CLIENT_REPLY_SESSION_REQUEST { 81 | log.Println("Got a session connection from client:", conn) 82 | request = make([]byte, 4) 83 | conn.Read(request) 84 | sessionId := natgo.BytesToInt32(request) 85 | log.Println("Get session id from client:", sessionId) 86 | response := make([]byte, 1) 87 | response[0] = natgo.CMD_CLIENT_REPLY_SESSION_RESPONSE 88 | conn.Write(response) 89 | log.Println("Send client reply session response") 90 | 91 | guestConn := waitingGuestConnectionPool[sessionId] 92 | log.Println("Get guest connection from pool:", guestConn) 93 | delete(waitingGuestConnectionPool, sessionId) 94 | if guestConn != nil { 95 | natgo.ConnectionExchange(conn, guestConn) 96 | } 97 | } 98 | 99 | return nil 100 | } 101 | 102 | func processMgrChannel(conn net.Conn) { 103 | for { 104 | buffer := make([]byte, 1) 105 | _, err := conn.Read(buffer) 106 | if err != nil { 107 | log.Println("Failed to read from client, ", err) 108 | conn.Close() 109 | return 110 | } 111 | cmd := buffer[0] 112 | if cmd == natgo.CMD_HEART_BEAT_REQUEST { 113 | log.Println("Get heartbeat request from client") 114 | rsp := []byte{natgo.CMD_HEART_BEAT_RESPONSE} 115 | mgrChannelLock.Lock() 116 | log.Println("Response heartbeat to client") 117 | _, err = conn.Write(rsp) 118 | mgrChannelLock.Unlock() 119 | if err != nil { 120 | log.Println("Failed to write client") 121 | conn.Close() 122 | return 123 | } 124 | } else if cmd == natgo.CMD_SERVER_START_SESSION_RESPONSE { 125 | //do nothing for now 126 | log.Println("Get response from client for start session") 127 | } 128 | } 129 | } 130 | 131 | func listenForGuests(guestPorts []string) { 132 | for _, port := range guestPorts { 133 | go listenForGuest(port) 134 | } 135 | } 136 | 137 | func listenForGuest(guestPort string) { 138 | log.Println("Start Guest thread on port " + guestPort) 139 | ln, err := net.Listen("tcp", ":" + guestPort) 140 | if err != nil { 141 | log.Println(err) 142 | panic(err) 143 | } 144 | log.Println("Listen on port:" + guestPort, ln.Addr()) 145 | defer ln.Close() 146 | 147 | for { 148 | guestConn, err := ln.Accept() 149 | if err != nil { 150 | log.Println(err) 151 | guestConn.Close() 152 | } else { 153 | log.Println("Got a connection from guest:", guestConn.RemoteAddr()) 154 | natConn := natConnectionPool[guestPort] 155 | if natConn != nil { 156 | connectNATAndGuest(natConn, guestConn, guestPort) 157 | } else { 158 | log.Println("No client register for this port, close guest.") 159 | guestConn.Close() 160 | } 161 | } 162 | } 163 | } 164 | 165 | func connectNATAndGuest(natConn net.Conn, guestConn net.Conn, guestPort string) { 166 | var sessionId int32 = rand.Int31() 167 | mgrChannelLock.Lock() 168 | err := natgo.ServerStartSessionRequest(natConn, sessionId, guestPort) 169 | mgrChannelLock.Unlock() 170 | if err == nil { 171 | log.Println("Get correct response, begin start session") 172 | waitingGuestConnectionPool[sessionId] = guestConn 173 | go timeoutForGuestConnection(sessionId) 174 | } else { 175 | log.Print("Get invalid response:") 176 | } 177 | } 178 | 179 | func timeoutForGuestConnection(sessionId int32) { 180 | time.Sleep(5 * time.Second) 181 | conn, ok := waitingGuestConnectionPool[sessionId] 182 | if ok { 183 | log.Println("Timeout to wait for connection from client, close the guest.") 184 | conn.Close() 185 | delete(waitingGuestConnectionPool, sessionId) 186 | } 187 | } 188 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | --------------------------------------------------------------------------------