mirror of
https://github.com/SagerNet/sing-box.git
synced 2025-06-13 21:54:13 +08:00
Compare commits
44 Commits
32c43a8f87
...
7b7820a322
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7b7820a322 | ||
![]() |
c38d3fb3b5 | ||
![]() |
b440c3371a | ||
![]() |
228bdfa243 | ||
![]() |
c13762f2b7 | ||
![]() |
32b7fc91a5 | ||
![]() |
07859befcd | ||
![]() |
ebff681aa7 | ||
![]() |
011dd16efb | ||
![]() |
d32a9f0f7c | ||
![]() |
9295aba05a | ||
![]() |
8f0dc74b41 | ||
![]() |
07475132c0 | ||
![]() |
1c85682f36 | ||
![]() |
5b4dfea740 | ||
![]() |
e01712fd40 | ||
![]() |
0e98b5fe44 | ||
![]() |
b10037bb57 | ||
![]() |
50bacf545b | ||
![]() |
5489daf126 | ||
![]() |
b5f828ad84 | ||
![]() |
16f034037b | ||
![]() |
75f4a3d4a8 | ||
![]() |
69a6dc50f3 | ||
![]() |
40e24a440e | ||
![]() |
a4c3367c71 | ||
![]() |
abfebd1e96 | ||
![]() |
877988b3e9 | ||
![]() |
f7c1ebd56d | ||
![]() |
a407c03497 | ||
![]() |
474efa5585 | ||
![]() |
6225ea1980 | ||
![]() |
aa6b2404ab | ||
![]() |
4c59a3cf7c | ||
![]() |
9fd37c7b02 | ||
![]() |
b21a79bc12 | ||
![]() |
d7d87436d7 | ||
![]() |
4f735529e5 | ||
![]() |
bca4b38fce | ||
![]() |
a8a5ae2e77 | ||
![]() |
8929b4161d | ||
![]() |
6fb79d5d72 | ||
![]() |
96eb98c00a | ||
![]() |
68ce9577c6 |
@ -2,7 +2,7 @@
|
|||||||
icon: material/alert-decagram
|
icon: material/alert-decagram
|
||||||
---
|
---
|
||||||
|
|
||||||
#### 1.12.0-alpha.15
|
#### 1.12.0-alpha.16
|
||||||
|
|
||||||
* Fixes and improvements
|
* Fixes and improvements
|
||||||
|
|
||||||
|
@ -20,12 +20,16 @@ type ID struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func ContextWithNewID(ctx context.Context) context.Context {
|
func ContextWithNewID(ctx context.Context) context.Context {
|
||||||
return context.WithValue(ctx, (*idKey)(nil), ID{
|
return ContextWithID(ctx, ID{
|
||||||
ID: rand.Uint32(),
|
ID: rand.Uint32(),
|
||||||
CreatedAt: time.Now(),
|
CreatedAt: time.Now(),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func ContextWithID(ctx context.Context, id ID) context.Context {
|
||||||
|
return context.WithValue(ctx, (*idKey)(nil), id)
|
||||||
|
}
|
||||||
|
|
||||||
func IDFromContext(ctx context.Context) (ID, bool) {
|
func IDFromContext(ctx context.Context) (ID, bool) {
|
||||||
id, loaded := ctx.Value((*idKey)(nil)).(ID)
|
id, loaded := ctx.Value((*idKey)(nil)).(ID)
|
||||||
return id, loaded
|
return id, loaded
|
||||||
|
@ -2,6 +2,7 @@ package v2rayhttp
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
std_bufio "bufio"
|
std_bufio "bufio"
|
||||||
|
"context"
|
||||||
"io"
|
"io"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -10,6 +11,7 @@ import (
|
|||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
"github.com/sagernet/sing/common/baderror"
|
"github.com/sagernet/sing/common/baderror"
|
||||||
"github.com/sagernet/sing/common/buf"
|
"github.com/sagernet/sing/common/buf"
|
||||||
@ -255,3 +257,11 @@ func (w *HTTP2ConnWrapper) Close() error {
|
|||||||
func (w *HTTP2ConnWrapper) Upstream() any {
|
func (w *HTTP2ConnWrapper) Upstream() any {
|
||||||
return w.ExtendedConn
|
return w.ExtendedConn
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func DupContext(ctx context.Context) context.Context {
|
||||||
|
id, loaded := log.IDFromContext(ctx)
|
||||||
|
if !loaded {
|
||||||
|
return context.Background()
|
||||||
|
}
|
||||||
|
return log.ContextWithID(context.Background(), id)
|
||||||
|
}
|
||||||
|
@ -132,7 +132,7 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
|||||||
if requestBody != nil {
|
if requestBody != nil {
|
||||||
conn = bufio.NewCachedConn(conn, requestBody)
|
conn = bufio.NewCachedConn(conn, requestBody)
|
||||||
}
|
}
|
||||||
s.handler.NewConnectionEx(request.Context(), conn, source, M.Socksaddr{}, nil)
|
s.handler.NewConnectionEx(DupContext(request.Context()), conn, source, M.Socksaddr{}, nil)
|
||||||
} else {
|
} else {
|
||||||
writer.WriteHeader(http.StatusOK)
|
writer.WriteHeader(http.StatusOK)
|
||||||
done := make(chan struct{})
|
done := make(chan struct{})
|
||||||
|
@ -12,6 +12,7 @@ import (
|
|||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
|
"github.com/sagernet/sing-box/transport/v2rayhttp"
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
E "github.com/sagernet/sing/common/exceptions"
|
E "github.com/sagernet/sing/common/exceptions"
|
||||||
"github.com/sagernet/sing/common/logger"
|
"github.com/sagernet/sing/common/logger"
|
||||||
@ -37,6 +38,7 @@ type Server struct {
|
|||||||
func NewServer(ctx context.Context, logger logger.ContextLogger, options option.V2RayHTTPUpgradeOptions, tlsConfig tls.ServerConfig, handler adapter.V2RayServerTransportHandler) (*Server, error) {
|
func NewServer(ctx context.Context, logger logger.ContextLogger, options option.V2RayHTTPUpgradeOptions, tlsConfig tls.ServerConfig, handler adapter.V2RayServerTransportHandler) (*Server, error) {
|
||||||
server := &Server{
|
server := &Server{
|
||||||
ctx: ctx,
|
ctx: ctx,
|
||||||
|
logger: logger,
|
||||||
tlsConfig: tlsConfig,
|
tlsConfig: tlsConfig,
|
||||||
handler: handler,
|
handler: handler,
|
||||||
host: options.Host,
|
host: options.Host,
|
||||||
@ -110,7 +112,7 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
|||||||
s.invalidRequest(writer, request, http.StatusInternalServerError, E.Cause(err, "hijack failed"))
|
s.invalidRequest(writer, request, http.StatusInternalServerError, E.Cause(err, "hijack failed"))
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
s.handler.NewConnectionEx(request.Context(), conn, sHttp.SourceAddress(request), M.Socksaddr{}, nil)
|
s.handler.NewConnectionEx(v2rayhttp.DupContext(request.Context()), conn, sHttp.SourceAddress(request), M.Socksaddr{}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) invalidRequest(writer http.ResponseWriter, request *http.Request, statusCode int, err error) {
|
func (s *Server) invalidRequest(writer http.ResponseWriter, request *http.Request, statusCode int, err error) {
|
||||||
|
@ -13,6 +13,7 @@ import (
|
|||||||
C "github.com/sagernet/sing-box/constant"
|
C "github.com/sagernet/sing-box/constant"
|
||||||
"github.com/sagernet/sing-box/log"
|
"github.com/sagernet/sing-box/log"
|
||||||
"github.com/sagernet/sing-box/option"
|
"github.com/sagernet/sing-box/option"
|
||||||
|
"github.com/sagernet/sing-box/transport/v2rayhttp"
|
||||||
"github.com/sagernet/sing/common"
|
"github.com/sagernet/sing/common"
|
||||||
"github.com/sagernet/sing/common/buf"
|
"github.com/sagernet/sing/common/buf"
|
||||||
"github.com/sagernet/sing/common/bufio"
|
"github.com/sagernet/sing/common/bufio"
|
||||||
@ -114,7 +115,7 @@ func (s *Server) ServeHTTP(writer http.ResponseWriter, request *http.Request) {
|
|||||||
if len(earlyData) > 0 {
|
if len(earlyData) > 0 {
|
||||||
conn = bufio.NewCachedConn(conn, buf.As(earlyData))
|
conn = bufio.NewCachedConn(conn, buf.As(earlyData))
|
||||||
}
|
}
|
||||||
s.handler.NewConnectionEx(request.Context(), conn, source, M.Socksaddr{}, nil)
|
s.handler.NewConnectionEx(v2rayhttp.DupContext(request.Context()), conn, source, M.Socksaddr{}, nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Server) invalidRequest(writer http.ResponseWriter, request *http.Request, statusCode int, err error) {
|
func (s *Server) invalidRequest(writer http.ResponseWriter, request *http.Request, statusCode int, err error) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user