Skip to content

Commit 76b27a3

Browse files
authored
Update common/xudp/xudp.go and common/mux/server.go
1 parent 15cf31f commit 76b27a3

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

common/mux/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ func (w *ServerWorker) handleStatusNew(ctx context.Context, meta *FrameMetadata,
177177
// Actually, it won't return an error in Xray-core's implementations.
178178
link, err := w.dispatcher.Dispatch(ctx, meta.Target)
179179
if err != nil {
180+
XUDPManager.Lock()
181+
delete(XUDPManager.Map, x.GlobalID)
182+
XUDPManager.Unlock()
180183
err = newError("failed to dispatch request to ", meta.Target).Base(err)
181184
if xudp.Show {
182185
fmt.Printf("XUDP new: %v err: %v\n", meta.GlobalID, err)

common/xudp/xudp.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ var AddrParser = protocol.NewAddressParser(
2525

2626
var (
2727
Show bool
28-
BaseKey [32]byte
28+
BaseKey []byte
2929
)
3030

3131
const (
@@ -37,24 +37,24 @@ func init() {
3737
if strings.ToLower(os.Getenv(EnvShow)) == "true" {
3838
Show = true
3939
}
40-
if raw := os.Getenv(EnvBaseKey); raw != "" {
41-
if key, _ := base64.RawURLEncoding.DecodeString(raw); len(key) == len(BaseKey) {
42-
copy(BaseKey[:], key)
40+
if raw, found := os.LookupEnv(EnvBaseKey); found {
41+
if BaseKey, _ = base64.RawURLEncoding.DecodeString(raw); len(BaseKey) == 32 {
4342
return
44-
} else {
45-
panic(EnvBaseKey + ": invalid value: " + raw)
4643
}
44+
panic(EnvBaseKey + ": invalid value: " + raw)
4745
}
48-
rand.Read(BaseKey[:])
46+
rand.Read(BaseKey)
4947
}
5048

5149
func GetGlobalID(ctx context.Context) (globalID [8]byte) {
5250
if inbound := session.InboundFromContext(ctx); inbound != nil && inbound.Source.Network == net.Network_UDP &&
5351
(inbound.Name == "dokodemo-door" || inbound.Name == "socks" || inbound.Name == "shadowsocks") {
54-
h := blake3.New(8, BaseKey[:])
52+
h := blake3.New(8, BaseKey)
5553
h.Write([]byte(inbound.Source.String()))
5654
copy(globalID[:], h.Sum(nil))
57-
fmt.Printf("XUDP inbound.Source.String(): %v\tglobalID: %v\n", inbound.Source.String(), globalID)
55+
if Show {
56+
fmt.Printf("XUDP inbound.Source.String(): %v\tglobalID: %v\n", inbound.Source.String(), globalID)
57+
}
5858
}
5959
return
6060
}

0 commit comments

Comments
 (0)