mirror of
https://github.com/v2fly/v2ray-core.git
synced 2025-01-17 23:06:30 -05:00
Fix usage of Mutex
This commit is contained in:
parent
3fbae6795a
commit
bb442b4f83
@ -46,8 +46,8 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
|
|||||||
readMutex.Lock()
|
readMutex.Lock()
|
||||||
writeMutex.Lock()
|
writeMutex.Lock()
|
||||||
|
|
||||||
go dumpInput(conn, input, writeMutex)
|
go dumpInput(conn, input, &writeMutex)
|
||||||
go dumpOutput(conn, output, readMutex)
|
go dumpOutput(conn, output, &readMutex)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
writeMutex.Lock()
|
writeMutex.Lock()
|
||||||
@ -61,12 +61,12 @@ func (vconn *FreedomConnection) Start(ray core.OutboundRay) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpInput(conn net.Conn, input <-chan []byte, finish sync.Mutex) {
|
func dumpInput(conn net.Conn, input <-chan []byte, finish *sync.Mutex) {
|
||||||
v2net.ChanToWriter(conn, input)
|
v2net.ChanToWriter(conn, input)
|
||||||
finish.Unlock()
|
finish.Unlock()
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpOutput(conn net.Conn, output chan<- []byte, finish sync.Mutex) {
|
func dumpOutput(conn net.Conn, output chan<- []byte, finish *sync.Mutex) {
|
||||||
v2net.ReaderToChan(output, conn)
|
v2net.ReaderToChan(output, conn)
|
||||||
finish.Unlock()
|
finish.Unlock()
|
||||||
close(output)
|
close(output)
|
||||||
|
@ -178,20 +178,20 @@ func (server *SocksServer) HandleConnection(connection net.Conn) error {
|
|||||||
readFinish.Lock()
|
readFinish.Lock()
|
||||||
writeFinish.Lock()
|
writeFinish.Lock()
|
||||||
|
|
||||||
go dumpInput(reader, input, readFinish)
|
go dumpInput(reader, input, &readFinish)
|
||||||
go dumpOutput(connection, output, writeFinish)
|
go dumpOutput(connection, output, &writeFinish)
|
||||||
writeFinish.Lock()
|
writeFinish.Lock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpInput(reader io.Reader, input chan<- []byte, finish sync.Mutex) {
|
func dumpInput(reader io.Reader, input chan<- []byte, finish *sync.Mutex) {
|
||||||
v2net.ReaderToChan(input, reader)
|
v2net.ReaderToChan(input, reader)
|
||||||
finish.Unlock()
|
finish.Unlock()
|
||||||
close(input)
|
close(input)
|
||||||
}
|
}
|
||||||
|
|
||||||
func dumpOutput(writer io.Writer, output <-chan []byte, finish sync.Mutex) {
|
func dumpOutput(writer io.Writer, output <-chan []byte, finish *sync.Mutex) {
|
||||||
v2net.ChanToWriter(writer, output)
|
v2net.ChanToWriter(writer, output)
|
||||||
finish.Unlock()
|
finish.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -82,7 +82,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
|
|||||||
readFinish.Lock()
|
readFinish.Lock()
|
||||||
writeFinish.Lock()
|
writeFinish.Lock()
|
||||||
|
|
||||||
go handleInput(request, connection, input, readFinish)
|
go handleInput(request, connection, input, &readFinish)
|
||||||
|
|
||||||
responseKey := md5.Sum(request.RequestKey[:])
|
responseKey := md5.Sum(request.RequestKey[:])
|
||||||
responseIV := md5.Sum(request.RequestIV[:])
|
responseIV := md5.Sum(request.RequestIV[:])
|
||||||
@ -100,7 +100,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
|
|||||||
if data, open := <-output; open {
|
if data, open := <-output; open {
|
||||||
buffer = append(buffer, data...)
|
buffer = append(buffer, data...)
|
||||||
responseWriter.Write(buffer)
|
responseWriter.Write(buffer)
|
||||||
go handleOutput(request, responseWriter, output, writeFinish)
|
go handleOutput(request, responseWriter, output, &writeFinish)
|
||||||
writeFinish.Lock()
|
writeFinish.Lock()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -112,7 +112,7 @@ func (handler *VMessInboundHandler) HandleConnection(connection net.Conn) error
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<- []byte, finish sync.Mutex) {
|
func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<- []byte, finish *sync.Mutex) {
|
||||||
defer close(input)
|
defer close(input)
|
||||||
defer finish.Unlock()
|
defer finish.Unlock()
|
||||||
|
|
||||||
@ -125,7 +125,7 @@ func handleInput(request *protocol.VMessRequest, reader io.Reader, input chan<-
|
|||||||
v2net.ReaderToChan(input, requestReader)
|
v2net.ReaderToChan(input, requestReader)
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-chan []byte, finish sync.Mutex) {
|
func handleOutput(request *protocol.VMessRequest, writer io.Writer, output <-chan []byte, finish *sync.Mutex) {
|
||||||
v2net.ChanToWriter(writer, output)
|
v2net.ChanToWriter(writer, output)
|
||||||
finish.Unlock()
|
finish.Unlock()
|
||||||
}
|
}
|
||||||
|
@ -114,8 +114,8 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
|
|||||||
requestFinish.Lock()
|
requestFinish.Lock()
|
||||||
responseFinish.Lock()
|
responseFinish.Lock()
|
||||||
|
|
||||||
go handleRequest(conn, request, input, requestFinish)
|
go handleRequest(conn, request, input, &requestFinish)
|
||||||
go handleResponse(conn, request, output, responseFinish)
|
go handleResponse(conn, request, output, &responseFinish)
|
||||||
|
|
||||||
requestFinish.Lock()
|
requestFinish.Lock()
|
||||||
conn.CloseWrite()
|
conn.CloseWrite()
|
||||||
@ -123,7 +123,7 @@ func startCommunicate(request *protocol.VMessRequest, dest v2net.Destination, ra
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-chan []byte, finish sync.Mutex) {
|
func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-chan []byte, finish *sync.Mutex) {
|
||||||
defer finish.Unlock()
|
defer finish.Unlock()
|
||||||
encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn)
|
encryptRequestWriter, err := v2io.NewAesEncryptWriter(request.RequestKey[:], request.RequestIV[:], conn)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -155,7 +155,7 @@ func handleRequest(conn *net.TCPConn, request *protocol.VMessRequest, input <-ch
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleResponse(conn *net.TCPConn, request *protocol.VMessRequest, output chan<- []byte, finish sync.Mutex) {
|
func handleResponse(conn *net.TCPConn, request *protocol.VMessRequest, output chan<- []byte, finish *sync.Mutex) {
|
||||||
defer finish.Unlock()
|
defer finish.Unlock()
|
||||||
defer close(output)
|
defer close(output)
|
||||||
responseKey := md5.Sum(request.RequestKey[:])
|
responseKey := md5.Sum(request.RequestKey[:])
|
||||||
|
Loading…
Reference in New Issue
Block a user